Download presentation
Presentation is loading. Please wait.
Published byDarlene Booth Modified over 6 years ago
1
Animationer ur Weiss kap. 16 Figurerna 16.20, 16.25
Spara som .pps!
2
4 // Insert x into the stack. 5 public void push( AnyType x ) 6 {
7 topOfStack = new ListNode<AnyType>(x,topOfStack); 8 } Figure part 1 The push routine for the linked list-based Stack class. = x new
3
... 13 // Remove the most recently inserted item from the stack. 14 public void pop ( ) 15 { if( isEmpty( ) ) throw UnderflowException(”ListStack pop”); topOfStack = topOfStack.next; 19 } Figure part 2 The pop routine for the linked list-based Stack class.
4
4 // Insert x into the queue. 5 public void enqueue( AnyType x ) 6 {
7 if( isEmpty( ) ) back = front = new ListNode<AnyType>( x ); 9 else back = back.next = new ListNode<AnyType>( x ); 11 } ... Figure part 1 The enqueue routine for the linked list-based Queue class. 3 2 x 1 front back 3 2 x 1 front back
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.