Lecture Notes on 25 Mar 2022 class Stack (object): def __init__(self): self.stack = [] # add an item to the top of the stack def push (self, item): self.stack.append (item) # remove an item from the top of the stack def pop (self): return self.stack.pop() # check the item on the top of the stack def peek (self): return self.stack[-1] # check if the stack is empty def is_empty (self): return (len(self.stack) == 0) # return the number of elements in the stack def size (self): return (len (self.stack)) class Queue (object): def __init__ (self): self.queue = [] # add an item to the end of the queue def enqueue (self, item): self.queue.append (item) # remove an item from the beginning of the queue def dequeue (self): return (self.queue.pop(0)) # check if the queue if empty def is_empty (self): return (len(self.queue) == 0) # return the size of the queue def size (self): return (len(self.queue)) * Pictorial Representation of Linked Lists: https://www.cs.utexas.edu/users/mitra/csSpring2022/cs313/notes/Singly_Linked_List.pdf * Application of Linked Lists - implementation of Stacks and Queues in constant time - Denote connectivity of vertices in a graph - adjacency list - Sparse matrix representation - Compact Hash Table - Dynamic memory allocation - linked list of free blocks * Doubly Linked List - Link has now next and previous pointers - traverse both ways in the linked list * Pictorial Representation https://www.cs.utexas.edu/users/mitra/csSpring2022/cs313/notes/Doubly_Linked_List.pdf * Circular Linked List - last link's next field points to the first link