Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

DATA STRUCTURES: 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 3) In Queue, ENQUEUE means____ whereas DEQUEUE refers____.


A) an insertion operation, a deletion operation.
B) End of the queue, defining a queue.
C) Both A and B.
D) None of the above are true.

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:

# A simple Python program for traversal of a linked list

# Node class

class Node:

# Function to initialise the node object

def __init__(self, data):

self.data = data # Assign data

self.next = None # Initialize next as null

# Linked List class contains a Node object

class LinkedList:

# Function to initialize head

def __init__(self):

self.head = None

# This function prints contents of linked list

# starting from head

def printList(self):

temp = self.head

while (temp):

print (temp.data)
temp = temp.next

# Start with the empty list

llist = LinkedList()

llist.head = Node(1)

second = Node(2)

third = Node(3)

llist.head.next = second; # Link first node with second

second.next = third; # Link second node with the third node

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.

You might also like