CSC 2200 Lecture Notes - Lecture 5: Abstract Data Type, Linked List, Data Element

11 views5 pages
CSC 2200 Lecture 5
Stacks
Stack
o Is an abstract data type , commonly used in most programming languages
o Behaves like a real world stack
o Example
Deck of cards
Pile of plates
o Allows operations at one end only
o Only access the top element of a stack
o LIFO data structure
Last in first out
o The element which is placed (inserted or deleted) last, is accessed first
o Insertion operation is called PUSH operation and removal operation is called POP
operation
o
Stack representation
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
o A stack can be implemented by means of Array, structure, pointer, and linked list
o Stack can either be a fixed size one or it may have a sense of dynamic resizing
Basic operations
o May involve initializing the stack, using it and then de-initializing
o A stack is used for the following two primary operations
Push()
Storing element on the stack
Pop()
Removing an element from the stack
Peek()
Get the top data element of the stack without removing it
isFull()
checks if stack is full
isEmpty()
checks if stack is empty
o At all times, we maintain a pointer to the last pushed data on the stack
o As this pointer always represents the top of the stack, hence named top
o The top pointer provides top value of the stack without removing it
Peek()
int peek()
{
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Notes+

Unlimited access to class notes and textbook notes.

YearlyBest Value
75% OFF
$8 USD/m
Monthly
$30 USD/m
You will be charged $96 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.