Link List ( Data Structure and ALgorithms ), Exams of Data Structures and Algorithms

These are the slides related to Data structure and Algorithms. A Detailed note on Link list .

Typology: Exams

2017/2018

Uploaded on 12/01/2018

almas1297
almas1297 🇵🇰

5

(1)

2 documents

1 / 44

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Link List
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c

Partial preview of the text

Download Link List ( Data Structure and ALgorithms ) and more Exams Data Structures and Algorithms in PDF only on Docsity!

Link List

What are Linked

Lists

 (^) A linked list is a linear data structure.  (^) Nodes make up linked lists.  (^) Nodes are structures made up of data and a pointer to another node.  (^) Usually the pointer is called next.

Types of lists There are two basic types of linked list

Singly Linked list

Doubly linked list

Singly Linked List  (^) Each node has only one link part  (^) Each link part contains the address of the next node in the list  (^) Link part of the last node contains NULL value which signifies the end of the node

Basic Operations on a list

  • (^) Creating a List
  • (^) Inserting an element in a

list

  • (^) Deleting an element from a

list

  • (^) Searching a list
  • (^) Reversing a list

Creating a node / / A simple node of a linked list struct node{ int data; nodenext; }start; start=NULL ; //start points at the first node initialised to NULL at beginning

To be called from main() as:- void main() { node* ptr; int data; cin>>data; ptr=create (data); }

Inserting the node in a SLL

There are 3 cases here:-

Insertion at the beginning

Insertion at the end

Insertion after a particular

node

//if the list is empty void insert_beg(node* p) { node* temp; if(start==NULL) { start=p; cout<<”\nNode inserted successfully at the beginning”; } else { } temp=start; start=p; p-

next=tem p; //making new node }

void insert_end(node* p) { node *q=start; if(start==NULL) { start= p; cout< <”
nNode insert ed succes sfully at the end…!

Inserting after an element

Here we again need to do 2 steps :-
 Make the next pointer of the node to be inserted
point to the next node of the node after which
you want to insert the node
 Make the next pointer of the node after which
the node is to be inserted, point to the node to
be inserted

void insert_after(int c,node* p) { node* q; q=start; for( int i=1; i<c; i+ +) { q= q-

li nk;

i

Deleting a node in SLL

Here also we have three cases:-
 Deleting the first node
Deleting the last node
Deleting the intermediate
node