Topc 5 ADT Flashcards
ADT
Abstract Data types
What are ADT’s? (Examples)
2D Arrays Linked List Stacks Queues Trees
Characteristics of stacks (3)
Vertical Last in; first out (LIFO) Collections (Unknown size; don’t know if it’s sorted)
Adding an element to a stack
.push()
Removing an element from a stack
.pop()
Reverse collection pseudocode
// declare an empty stack int count = 0 loop while collection.hasNext() stack.push(collection.getNext() ) count ++; end loop loop i from 0 to count-1 newarray[i] = stack.pop() end loop
Characteristics of a Queue
Horizontal First in; first out (FIFO)
Array to Stack pseudocode
loop i from 0 to array.length-1 S.push(array[i]) end loop (same can be done with queues; except enqueue)
Printing out a stack pseudocode
loop while not stack.isEmpty() output( stack.pop() ) end loop
Adding an item to a Queue
.enqueue()
Removing an item from a Queue
.dequeue()
Real world examples of a Queue
Printer Queues Supermarket Queues
Static (3)
Size determined at creation Not good use of memory space For loops
Dynamic (4)
Changes size Nodes and pointers Good use of memory space While loops
Accessing element in 2D arrays
array[row][column]