Slides - Stack and Queue

Slides - Stack and Queue - Stacks Data structure stack head...

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

View Full Document Right Arrow Icon
1 Stacks Data structure • stack head (head node) • stack data node (link node) Basic stack operations -- push -- pop -- stack top Stack Algorithms -- create stack -- push stack -- pop stack -- . . .
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 Algorithm createStack // create and initialize stack structure. allocate memory for stack head set count to 0 set top to null return stack head Algorithm pushStack // insert one item into the stack. allocate new node store data in new node make current top node the second node make new node the top increment stack count
Background image of page 2
3 Algorithm popStack Algorithm stackTop Algorithm destroyStack // release all nodes in stack and the stack itself. if (stack not empty) loop (stack not empty) delete top node end loop end if delete stack head
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 ADT stack structure // stack ADT type definitions typedef struct node { int data; struct node *link; } STACK-NODE; typedef struct { int count; STACK-NODE *top; } STACK;
Background image of page 4
5 STACK *createStack( void ) { STACK *stack; stack = (STACK *) malloc( sizeof (STACK) ); if (stack ) { stack->count = 0; stack->top = NULL; } return stack; } void destroyStack ( STACK *stack) { STACK-NODE *temp;
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.

Page1 / 15

Slides - Stack and Queue - Stacks Data structure stack head...

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