LSQ and Trees

LSQ and Trees - CSC2100a Tutorial Lists, Stacks and Queues...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSC2100a Tutorial Lists, Stacks and Queues * Part 2 * Spring 2006/2007
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Stack - example 1 • Reverse a string • We can do that using stack ! I am sleeping. .gnipeels ma I reverse
Background image of page 2
3 Stack - example 1 /* Input the string */ while (cin >> ch, ch != '\n') s.push(ch); /* Output the string */ cout<<"The reversed string is:“<<endl; while (s.isEmpty()) cout<<s.topAndPop(); cout<<endl; i n g . I am sleep Push! .gnipeelsm Pop! I a
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Stack - example 2 • Recursive function template <class Object> void printList( ListNode<Object> *p) { if (p == NULL) return; cout << p->element << endl; printList( p->next ); } • A bad use of recursion: printing a linked list. Why?
Background image of page 4
Stack - example 2 • Function calls – When a function calls another function, the computer must remember all the local variables, registers, etc. – For example there are three subprograms called A, B and C – A calls B, B calls C – A will not finish until B finishes. – B will not finish until C finishes.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 25

LSQ and Trees - CSC2100a Tutorial Lists, Stacks and Queues...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online