0% found this document useful (0 votes)
62 views23 pages

Mr.S.Habib Hussain, Ap/Cse, Mahalakshmi Engineering College, Trichy - 621 213

The document contains 18 multiple choice questions related to data structures such as stacks, queues, linked lists, trees, and graphs. It discusses concepts like headers in linked lists, traversing doubly linked lists, circular linked lists, priority queues, representing stacks using arrays, applications of queues, testing for empty queues, abstract data types, evaluating postfix expressions, comparing arrays and structures, applications of stacks, and differentiating between stacks and queues. Sample code is provided for some questions to demonstrate linked list traversal and stack implementation using arrays.

Uploaded by

Anitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views23 pages

Mr.S.Habib Hussain, Ap/Cse, Mahalakshmi Engineering College, Trichy - 621 213

The document contains 18 multiple choice questions related to data structures such as stacks, queues, linked lists, trees, and graphs. It discusses concepts like headers in linked lists, traversing doubly linked lists, circular linked lists, priority queues, representing stacks using arrays, applications of queues, testing for empty queues, abstract data types, evaluating postfix expressions, comparing arrays and structures, applications of stacks, and differentiating between stacks and queues. Sample code is provided for some questions to demonstrate linked list traversal and stack implementation using arrays.

Uploaded by

Anitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Subject Code: CS6202 Subject Name: PDS - I

st
Semester / Year: II / 1 Branch: CSE

UNIT – III
LINEAR STRUCTURES - LIST
PART – A (2 Marks)
1. What is the importance of header nodes? [Nov/Dec 2012]
Answer :
Header node of the linked list is the first element in the list and it stores the
number of elements in the list. It points to the first data element of the list.
2. Write simple code to traverse through DLL. [May/June 2009]
Answer :
#include<stdio.h>
struct node
{
int item;
struct node *link
};
main()
{
struct node *start,*list;
int i;
start = (struct node *)malloc(sizeof(struct node));
list = start;
start->link = NULL;
for(i=0;i<10;i++)
{
list->item = i;
list->link = (struct node *)malloc(sizeof(struct node));
}
list->link = NULL;
while(start != NULL)
{
printf("%d\n",start->item);
start = start->link;
}
}
3. What is circular linked list ? Give example .[April/May 2008]
Answer :
Circularly linked list is a collection of nodes , where each node is a structure containing
the element and a pointer to a structure containing its successor.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 1
The pointer field of the last node points to the address of the first node. Thus the linked
list becomes circular.

4. What is a priority queue. [May/June 2009, April/May 2010, Nov/Dec 2005]


Answer :
Priority queue is a data structure that allows at least the following two operations.
1. Insert-inserts an element at the end of the list called the rear.
2. DeleteMin-Finds, returns and removes the minimum element in the priority Queue.

Operations:
Insert
DeleteMin

5. What is stack? How it can be represented in “C” using arrays? [April/May 2008]
Answer :
Stack is a data structure in which both insertion and deletion occur at one end only.
Stack is maintained with a single pointer to the top of the list of elements. The other name of
stack is Last-in -First-out list.
Associated with each stack is the top of stack, tos, which is -1 for an empty stack (this is
how an empty stack is initialized). To push some element x onto the stack, we increment tos
and then set STACK[tos] = x, where STACK is the array representing the actual stack. To pop,
we set the return value to STACK[tos] and then decrement tos.

6. Justify queue as ADT. [May/June 2007]


Answer :
Queue is a list in which insertion is done at one end called the rear and deletion is performed at
another called front.
e.g: Ticket counter.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 2
Phone calls waiting in a queue for the operator to receive.
7. When will be a Circular queue empty? [Nov/Dec2009]
Answer :
To test for an empty circular queue, we have to check whether REAR=HEAD where REAR is a
pointer pointing to the last node in a queue and HEAD is a pointer that pointer to the dummy
header. In the case of array implementation of queue, the condition to be checked for an empty
queue is READ<FRONT.
8. State any two application of queue.[Nov/Dec 2007]
Answer :
Graph Algorithm
Priority Algorithm
Job scheduling
Categorizing Data
9. What is an abstract data type (ADT).[ May/Jun 2005]
Answer :
An ADT is a set of operation. Abstract data types are mathematical abstractions. Example.
Objects such as list, set and graph along their operations can be viewed as ADT's.

10. What are the steps involved in balancing symbols?


Answer :
Make an empty stack.
Read characters until end of file.
If the character is an opening symbol, then push it onto the stack.
If it is a closing symbol
Then
If the stack is empty
Report an error
Otherwise pop the stack
If the symbol popped is not the corresponding opening symbol
Then
Report an error
If the stack is not empty at the end of file
Then
Report an error

11. What are the steps for evaluating postfix expression? [Nov/Dec2009]
MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 3
Answer :

a. Scan the Postfix string from left to right.


b. Initialize an empty stack.
c. If the scanned character is an operand, add it to the stack. If the scanned character is an
operator, there will be atleast two operands in the stack.
i. If the scanned character is an Operator, then we store the top most element of
the stack(topStack) in a variable temp. Pop the stack. Now evaluate
topStack(Operator)temp. Let the result of this operation be retVal. Pop the stack
and Push retVal into the stack.
ii. Repeat this step till all the characters are scanned.
d. After all characters are scanned, we will have only one element in the stack. Return
topStack.

12. Differentiate array and structures. [Nov/Dec 2011]


Answer :
Array elements are homogeneous. Structure elements are of different data type.
Array allocates static memory and uses index / subscript for accessing elements of the
array. Structures allocate dynamic memory and uses (.) operator for accessing the member
of a structure.
Array is a pointer to the first element of it. Structure is not a pointer
Array element access takes less time in comparison with structures.

13. What is ADT.Give an Example.[Nov/Dec 2011]


Answer :
An ADT is a set of operation. Abstract data types are mathematical abstractions. Example.
Objects such as list, set and graph along their operations can be viewed as ADT's.
14. Give any Four application of stack.[Nov/Dec 2011]
Answer :
Balancing symbols.
Evaluating Postfix Expression.
Infix to postfix conversion.
Function calls.

15. Compare and contrast stack and queue. [Nov/Dec 2011]

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 4
Answer :

A stack is generally First In, Last Out, and a queue is First In First Out.
Item can be added or removed only at one end in stack and in a queue insertion at the
rear and deletion from the front.
The basic operation of stack are 'push' and 'pop', on other hand of queue are 'enque'
and 'dequeue'.

16. What are the postfix and prefix forms of the expression A+B*(C-D)/(E-F)?-[May/June
2012]
Answer :
Prefix expressions : +A/*B-CD-EF
Postfix expressions : ABCD-*EF-/+

17. Define queue. [May/June 2012]


Answer :
Queue is a list in which insertion is done at one end called the rear and deletion is
performed at another called front.
e.g: Ticket counter.
Phone calls waiting in a queue for the operator to receive.
18. Convert the expression to equivalent Reverse Polish and Polish notations.
(i) A+(B-C/D)-E
Polish notations : -+A-B/CDE
Reverse Polish notations : ABCD/-+E-
(ii) ((A + B) * C – (D – E) ^ (F + G))
Polish notations : -*+ABC^-DE+FG
Reverse Polish notations : AB+C*DE-FG+^-
(iii) X+Y*(A-B)/(C-D)
Polish notations : +X/*Y-AB-CD
Reverse Polish notations : XYAB-*CD-/+

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 5
PART – B (16 Marks)

1. Write algorithms for insertion and deletion of elements in a [May/June 2007, Nov/Dec2009,
May/June 2012, May/June 2009, April/May 2010]
(i) Stack.
Solution: Insertion function:-
PROCEDURE ADD(ITEM, STACK, N, TOP)
[Inserts ‘item’ into the ‘stack’ of maximum size ‘n’, top is the number of elements currently in
‘stack’.]
1. [Overflow ?]
if (TOP >= N)
write Stack is full.
return.
2. [Increment top]
top <-- top + 1
3. [Insert Element]
stack [top] <-- item.
4. [FINISH]
return.
Deletion Function :-
PROCEDURE DELETE(ITEM, STACK, TOP)
[Deletes ‘item’ from the ‘stack’, top is the number of elements currently in ‘stack’.]

1. [Underflow ?]
if (TOP <= 0)
write Stack is empty.
return.
2. [Deleting Element]
item <-- stack[top]
3. [Decrementing top]
top <-- top - 1
4. [FINISH]
return (top).
(ii) Queue.
Solution:

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 6
PROCEDURE ADD(QUEUE, F, R, N, item)
[This will inserts ‘item’ in the ‘queue’ after ‘R (rare)’ where ‘n’ is size of array.]
1. [Overflow ?]
if (R >= N)
write Stack is full.
return.
2. [Increment R]
R <-- R + 1
3. [Insert Element]
QUEUE [R] <-- item.
4. [Setting the ‘F (Front)’ pointer]
if (F=0)
F=1
return.
PROCEDURE DELETE(QUEUE, F, R, item)
[Deletes ‘item’ from the ‘stack’, ‘F’ is the Front end pointer and ‘R’ is the rare end pointer]
1. [Underflow ?]
if (R <= 0)
write Stack is empty.
return.
2. [Deleting Element]
item <-- QUEUE[F]
3. [Incrementing F]
F <-- F + 1
4. [Checking for empty queue]
if (F > R)
then F <-- R <-- 0
return.

2. What is a doubly linked list? State the advantages of using doubly linked list. Write the
procedure to add and delete an element from the doubly linked list. - April/May 2008
Solution:
A doubly linked list, in computer science, is a linked data structure that consists of a set of sequentially
linked records called nodes. Each node contains two fields, called links that are references to the
previous and to the next node in the sequence of nodes. The beginning and ending

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 7
nodes’ previous and next links, respectively, point to some kind of terminator, typically a sentinel
node or null, to facilitate traversal of the list.

Advantages of using doubly linked list :


Doubly linked list offers easy implementation of many operations, whereas singly linked list requires
more info for the same operation. Like for the deletion of a node in a singly linked list. we definitely need
the ptr to node previous to it..
But in case of doubly linked list, we just need the ptr to the node being deleted as shown below.(I m
taking a general case below, have nor mentioned the boundary conditions)
ptr->right->left=ptr->left;
ptr->left->right=ptr->right;
free(ptr);
But then some tradeoffs are there. Doubly linked list occupy more space and often more operations are
required for the similar tasks as compared to singly linked lists.
Inserting a node at the start of list :
Algorithm :
 Update the next pointer of the new node to the head node and make prev pointer of the
new node as NULL
 Now update head node’s prev pointer to point to new node and make new node as head
node.
Inserting a node in between of list :
Algorithm :
 Traverse the list to the position where the new node is to be inserted. Let’s call this node
as Position Node (we have to insert new node just next to it).
 Make the next pointer of new pointer to point to next node of position node. Also make
the prev point of new node to point to position node.
 Now point position node’s next pointer to new node and prev node of next node of
position node to point to new node.
Inserting a node at the end of the list :
Algorithm :
 Traverse the list to end. Let’s call the current last node of list as Last node.
 Make next pointer of New node to point to NULL and prev pointer of new node to point
to Last node.
 Update next pointer of Last node to point to new Node.
Delete a node in a Doubly Linked List
a) Original Doubly Linked List

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 8
(a) After deletion of head node

(a) After deletion of middle node

(a) After deletion of last node

Algorithm:
Let the node to be deleted is del.
1) If node to be deleted is head node, then change the head pointer to next current head.
2) Set next of previous to del, if previous to del exists.
3) Set prev of next to del, if next to del exists.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 9
.
3. What are the advantages of circular linked list? Write down the various primitive operations
performed on circular linked list. Write the algorithm for insertion of element in the circular
linked list.- Nov/Dec 2006

Solution: In such a list traversing through a list will be through a circular path. Starting at a point in the
list and traversing the entire list ends up at the starting point. Any point in the list can be reached from
any other point.In it the last node does not contain NULL pointer. Instead the last node contains a
pointer that has the address of first node and thus points back to the first node. It is shown below:

Advantages:

1. If we are at a node, then we can go to any node. But in linear linked list it is not possible to go to
previous node.
2. It saves time when we have to go to the first node from the last node. It can be done in single step
because there is no need to traverse the in between nodes. But in double linked list, we will have to go
through in between nodes.
In a Circular link list with create, insert, delete, display operations using structure pointer.
Insertion at the front of Circular linked list:
PROCEDURE FOR INSERTION A NODE AT THE BEGINNING OF LIST
Step1. Create the new node
Step2. Set the new node’s next to itself (circular!)
Step3. If the list is empty,return new node.
Step4. Set our new node’s next to the front.
Step5. Set tail’s next to our new node.
Step6. Return the end of the list.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 10
ALGORITHM FOR INSERTION AT THE FRONT OF CIRCULAR LINKED LIST

node* AddFront(node* tail, int num)


{
node *temp = (node*)malloc(sizeof(node));
temp->data = num;
temp->next = temp;
if (tail == NULL)
return temp;
temp->next = tail->next;
tail->next = temp;
return tail;
}

INSERTION IN THE MIDDLE OF THE CIRCULAR LINKED LIST

InsertAtlocDll(info,next,start,end,loc,size)
1.set nloc = loc-1 , n=1
2.create a new node and address in assigned to ptr.
3.check[overflow] if(ptr=NULL)
write:overflow and exit
4.set Info[ptr]=item;
5.if(start=NULL)
set next[ptr] = NULL
set start = ptr
else if(nloc<=size)

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 11
repeat steps a and b while(n != nloc)

a. loc = next[loc]
b. n = n+1
[end while]
next[ptr] = next[loc]
next[loc] = ptr
else
set last = start;
repeat step (a) while(next[last]!= NULL)
a. last=next[last]
[end while]
last->next = ptr ;
[end if]
6.Exit.

Insertion at the end of Circular linked list:

PROCEDURE FOR INSERTION A NODE AT THE END OF LIST


Step1. Create the new node
Step2. Set the new node’s next to itself (circular!)
Step3. If the list is empty,return new node.
Step4. Set our new node’s next to the front.
Step5. Set tail’s next to our new node.
Step6. Return the end of the list.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 12
ALGORITHM FOR INSERTION AT THE END OF CIRCULAR LINKED LIST

node* AddEnd(node* tail, int num)


{
node *temp = (node*)malloc(sizeof(node));
temp->data = num;
temp->next = temp;
if (tail == NULL)
return temp;
temp->next = tail->next;
tail->next = temp;
return temp;
}

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 13
4. Compare the following with suitable example. - Nov/Dec 2009
(i)Linked list and array

Solution:
Difference Between array and Linked List : Array Vs Linked List

1. Access :Random / Sequential

Stack elements can be randomly Accessed using Subscript Variable


e.g a[0],a[1],a[3] can be randomly accessed
While In Linked List We have to Traverse Through the Linked List for Accessing Element.
So O(n) Time required for Accessing Element .
Generally In linked List Elements are accessed Sequentially.

2 . Memory Structure :

Stack is stored in contiguous Memory Locations , i.e Suppose first element is Stored at 2000
then Second Integer element will be stored at 2002 .
But It is not necessary to store next element at the Consecutive memory Location .
Element is stored at any available Location , but the Pointer to that memory location is stored in
Previous Node.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 14
3 . Insertion / Deletion

As the Array elements are stored in Consecutive memory Locations , so While Inserting
elements ,we have to create space for Insertion.
So More time required for Creating space and Inserting Element
Similarly We have to Delete the Element from given Location and thenShift All successive
elements up by 1 position
In Linked List we have to Just Change the Pointer address field (Pointer),So Insertion and
Deletion Operations are quite easy to implement

4 . Memory Allocation :

Memory Should be allocated at Compile-Time in Stack . i.e at the time when Programmer
is Writing Program
In Linked list memory can be allocated at Run-Time , i.e After executing Program
Stack uses Static Memory Allocation and Linked List Uses Dynamic Memory Allocation

Dynamic Memory allocation functions – malloc,calloc,delete etc…


(ii)Singly linked list and doubly linked list.

Singly Linked List vs Doubly Linked List


Linked list is a linear data structure that is used to store a collection of data. A linked list allocates
memory to its elements separately in its own block of memory and the overall structure is obtained by
linking these elements as links in a chain. A singly linked list is made up of a sequence of nodes and
each node has a reference to the next node in the sequence. A doubly linked list contains a sequence
of nodes in which each node contains a reference to the next node as well as to the previous node.
Singly Linked List
Each element in a singly linked list has two fields as shown in Figure 1. The data field holds the actual
data stored and the next field holds the reference to the next element in the chain. The first element of
the linked list is stored as the head of the linked list.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 15
Figure 2 depicts a singly linked list with three elements. Each element stores its data and all elements
except the last one store a reference to the next element. Last element holds a null value in its next
field. Any element in the list can be accessed by starting at the head and following the next pointer until
you meet the required element.
Doubly Linked List
Each element in a doubly linked list has three fields as shown in Figure 3. Similar to singly linked list,
the data field holds the actual data stored and the next field holds the reference to the next element in
the chain. Additionally, the previous field holds the reference to the previous element in the chain. The
first element of the linked list is stored as the head of the linked list.
Difference between Singly Linked List and Doubly Linked List
Each element in the singly linked list contains a reference to the next element in the list, while each
element in the doubly linked list contains references to the next element as well as the previous
element in the list. Doubly linked lists require more space for each element in the list and elementary
operations such as insertion and deletion is more complex since they have to deal with two references.
But doubly link lists allow easier manipulation since it allows traversing the list in forward and backward
directions.

Figure 4 depicts a doubly linked list with three elements. All the intermediate elements store references
to the first and previous elements. Last element in the list holds a null value in its next field and the first
element in the list holds a null value in its previous field. Doubly linked list can be traversed forward by
following the next references in each element and similarly can be traversed backwards using the
previous references in each element.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 16
5. Explain how array is represented in memory as row major and column major method.(8) -
Nov/Dec2009
A row major matrix is an array of row vectors and a column major matrix is an array of column
vectors.
We also need to decide whether non-matrix vectors are going to be row vectors or column vectors. We
could decide to be consistent and use row vectors with row major matrices and column vectors with
column major matrices, but switching them can have benefits.

This leaves us with 4 potential scenarios, each with a slightly different set of ramifications:

1. Row vectors with row major matrices:


o The vector is the left operand of the transform.
o Vector transforms are dot products between the vector and the column elements of the
matrix.
o Matrix multiplication order is local space on the left and world space on the right.
o Matrix vectors are the mapping of local space scalar units to world space vectors.
2. Row vectors with column major matrices:
o The vector is the left operand of the transform.
o Vector transforms are dot products between the vector and the vectors of the matrix.
o Matrix multiplication order is local space on the left and world space on the right.
o Matrix vectors are the planes of the local frame of reference.
3. Column vectors with row major matrices:
o The vector is the right operand of the transform.
o Vector transforms are dot products between the vectors of the matrix and the vector.
o Matrix multiplication order is world space on the left and local space on the right.
o Matrix vectors are the planes of the local frame of reference.
4. Column vectors with column major matrices:
o The vector is the right operand of the transform.
o Vector transforms are dot products between the row elements of the matrix and the
vector.
o Matrix multiplication order is world space on the left and local space on the right.
o Matrix vectors are the mapping of local space scalar units to world space vectors.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 17
6. Write suitable ADT operations to perform insertion, deletion and display in Doubly Linked
list. -Nov/Dec 2011

A Doubly linked list is a linked list in which each node has three fields namely data field, forward
link (FLINK) and Backward Link (BLINK). FLINK points to the successor node in the list whereas
BLINK points to the predecessor node.

STRUCTURE DECLARATION : -

Struct Node

int Element;

Struct Node *FLINK;

Struct Node *BLINK


};

ROUTINE TO INSERT AN ELEMENT IN A DOUBLY LINKED LIST

void Insert (int X, list L, position P)


{
Struct Node * Newnode;
Newnode = malloc (size of (Struct Node));
If (Newnode ! = NULL)
{
Newnode →Element = X;
Newnode →Flink = P Flink;

P →Flink →Blink = Newnode;


P →Flink = Newnode ;
Newnode →Blink = P;

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 18
ROUTINE TO DELETE AN ELEMENT

void Delete (int X, List L)


{
position P;
P = Find (X, L);
If ( IsLast (P, L))
{
Temp = P;
P →Blink →Flink = NULL;
free (Temp);
}
else
{
Temp = P;
P →Blink→ Flink = P→Flink;
P →Flink →Blink = P→Blink;
free (Temp);
}
}

Advantage

* Deletion operation is easier.

* Finding the predecessor & Successor of a node is easier.

Disadvantage

* More Memory Space is required since it has two pointers.

7. Write an algorithm to perform addition and deletion in a linked list.(8) -May/June 2012,
May/June 2009

Singly-linked list. Removal (deletion) operation.

There are four cases, which can occur while removing the node. These cases are similar to the cases
in add operation. We have the same four situations, but the order of algorithm actions is opposite.
Notice, that removal algorithm includes the disposal of the deleted node, which may be unnecessary in
languages with automatic garbage collection (i.e., Java).

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 19
List has only one node

When list has only one node, which is indicated by the condition, that the head points to the same node
as the tail, the removal is quite simple. Algorithm disposes the node, pointed by head (or tail) and sets
both head and tail to NULL.

Remove first

In this case, first node (current head node) is removed from the list.

It can be done in two steps:

1. Update head link to point to the node, next to the head.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 20
2. Dispose removed node.

Remove last

In this case, last node (current tail node) is removed from the list. This operation is a bit more tricky,
than removing the first node, because algorithm should find a node, which is previous to the tail first.

It can be done in three steps:

1. Update tail link to point to the node, before the tail. In order to find it, list should be traversed
first, beginning from the head.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 21
2. Set next link of the new tail to NULL.

3. Dispose removed node.

General case

In general case, node to be removed is always located between two list nodes. Head and tail links are
not updated in this case.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 22
Such a removal can be done in two steps:

1. Update next link of the previous node, to point to the next node, relative to the removed node.

2. Dispose removed node.

MR.S.HABIB HUSSAIN, AP/CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY – 621 213. Page 23

You might also like