UNIT 2 Supriya (Single Link List)
UNIT 2 Supriya (Single Link List)
By,
Supriya Panigrahy
Deptt. of CSE
C. V. Raman Global University
Bhubaneswar
Array vs Link list
CONTENT
Introduction to Link list
2
Advantages of Array Data Structure
• Array is a data structure where elements are
stored in consecutive memory locations.
• Memory usage - In linked list, node occupies more memory than array.
Each node of the linked list occupies two types of variables, i.e., one is a
simple variable, and another one is the pointer variable.
Array
Linked List
NULL
10 27 -36 16
7
LINKED LIST
12 45 17 NL
Start
• A linked list is a series of connected nodes
• Each node contains at least
– A piece of data (any type)
– Pointer to the next node in the list
• Start: pointer to the first node
node
• The last node points to NULL
12
data pointer
8
9
• A singly linked list is a
concrete data structure
consisting of a sequence of
next
nodes
• Also called as one-way list
• Each node stores
– element node
elem
– link to the next node
10
SINGLY LINK LIST:
⮚ Linked List can be defined as collection of objects called nodes that are
randomly stored in the memory.
⮚ A node contains two fields i.e., data stored at that particular address and the
pointer which contains the address of the next node in the memory.
13
Creation of Single Linked List
• Print, overflow
• exit
• else
• PTR=(NODE*) malloc (size of(node))//create new
node from memory and assign its address to PTR.
• End if
• Step2: PTR->info=item
Suppose we want to delete the node that succeeds the node which contains data value 4 .
OPERATIONS ON SINGLY LINK LIST
Case 3: Deleting After a Given Node in a Linked List