Professional Documents
Culture Documents
Linked List
Linked List
RECALL TEST:
Q 1) A queue follows __________
A) FIFO (First In First Out) principle
B) LIFO (Last In First Out) principle
C) Ordered list
D) Linear tree
Q 2) If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a
time, in what order will they be removed?
A) ABCD
B) DCBA
C) DCAB
D) ABDC
Q 4) What is the most appropriate data structure to print elements of queue in reverse
order?
A) Stack
B) List
C) Sorting
D) None of these
Q 5) The maximum size of the queue ?
A) can be changed
B) cannot be changed
C) Independent
D) None of these
LINKED LIST:
A linked list is a collection of nodes. The first node is called the head, and it’s used as the
starting point for any iteration through the list. The last node must have its next reference
pointing to None to determine the end of the list. Linked Lists can be of two types, Singly
Linked List and Doubly Linked List. Singly Linked List is as follows:
CODE:
# Node class
class Node:
class LinkedList:
def __init__(self):
self.head = None
def printList(self):
temp = self.head
while (temp):
print (temp.data)
temp = temp.next
llist = LinkedList()
llist.head = Node(1)
second = Node(2)
third = Node(3)
llist.printList()
Output:
1 2 3
PRACTICE QUESTIONS:
1. Write a program to Store 5 employee ID numbers in an organization using Linked Lists.
2. Write a program to Store 4 of your best friend names using Linked Lists.