0% found this document useful (0 votes)
11 views26 pages

Stack Notes

The document illustrates the operations of a stack data structure, including push and pop actions. It details the state of the stack after each operation, including the last inserted elements and the pointer's position. Additionally, it demonstrates handling a full stack and the behavior when attempting to pop from an empty stack.

Uploaded by

iamjackalusa007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views26 pages

Stack Notes

The document illustrates the operations of a stack data structure, including push and pop actions. It details the state of the stack after each operation, including the last inserted elements and the pointer's position. Additionally, it demonstrates handling a full stack and the behavior when attempting to pop from an empty stack.

Uploaded by

iamjackalusa007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PUSH

Last Inserted 1 Stack


PUSH
4

Last Inserted 6
1 Stack
POP

Last Inserted 4
6
1 Stack
POP

Last Inserted 6
1 Stack
POP

Last Inserted 1 Stack


Stack Array
Implementation
2
4
6
1
Stack
1 6 4 2
Array/ List
Pointer = -1 PUSH
8

0 1 2 3
Stac
k
Pointer = 0 PUSH
5
8
0 1 2 3
Stac
k
Pointer = 1 PUSH
2
8 5
0 1 2 3
Stac
k
Pointer = 2 PEEK

8 5 2 2
0 1 2 3
Stac
k
Pointer = 2 PUSH
9
8 5 2
0 1 2 3
Stac
k
Pointer = 3 PUSH
Stack is full

6
8 5 2 9
0 1 2 3
Stac
k
Pointer = 3 POP

8 5 2 9
0 1 2 3
Stac
k
Pointer = 2 POP
9
8 5 2
0 1 2 3
Stac
k
Pointer = 1 POP
PEEK
2
8 5 5
0 1 2 3
Stac
k
Pointer = 1 POP

8 5
0 1 2 3
Stac
k
Pointer = 0 POP
5
8
0 1 2 3
Stac
k
Pointer = -1 POP
8

0 1 2 3
Stac
k
Pointer = -1 Stack is empty POP

0 1 2 3
Stac
k
Example

You might also like