SlideShare uma empresa Scribd logo
1 de 11
Baixar para ler offline
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
/* Doubly Linked List Acts Like Stack */
#include<stdio.h>
#include<stdlib.h>
struct node
{
struct node *llink;
int info;
struct node *rlink;
};
typedef struct node NODE;
void ins_first(NODE**, int);
int del_first(NODE**);
void display(NODE*);
int main()
{
NODE *first=NULL;
int choice, item;
for(;;)
{
printf("Operation Resarch On Doubly Linked Listn");
printf("Program Acts Like Stackn");
printf("1.Push OR Insert Frontn");
printf("2.Pop OR Delete Frontn");
printf("3.Displayn");
printf("4.Exitn");
printf("Enter U R Choicen");
scanf("%d", &choice);
printf("nn");
switch(choice)
{
case 1 : printf("Enter The Item To Insertn");
scanf("%d", &item);
printf("nn");
ins_first(&first, item);
break;
case 2 : item=del_first(&first);
if(item!='0')
printf("Deleted Element Is %dnn", item);
break;
case 3 : printf("Contents Of Stack Aren");
display(first);
break;
default : exit(0);
}
}
return 1;
}

P a g e |1
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
void ins_first(NODE **first, int item)
{
NODE *newn;
newn=(NODE*)malloc(sizeof(NODE));
newn->llink=NULL;
newn->info=item;
if(*first==NULL)
{
newn->rlink=NULL;
*first=newn;
}
else
{
newn->rlink=*first;
newn->rlink->llink=newn; /*Hihgly IMP */
*first=newn;
}
}
int del_first(NODE **first)
{
int item;
NODE *temp;
if(*first==NULL)
{
printf("Stack IS Underflownn");
return('0');
}
temp=*first;
item=temp->info;
*first=temp->rlink; /* *first->llink=NULL Is An Error. */
free(temp);
return item;
}
void display(NODE *first)
{
NODE *temp;
temp=first;
if(first==NULL)
{
printf("Stack Is Emptynn");
}
else
{
while(temp->rlink!=NULL)
{
printf("%dn", temp->info);
temp=temp->rlink;
}
printf("%dnn", temp->info);
}
}

P a g e |2
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
/* Doubly Linked List */
Insert Last
void ins_last(NODE **first, int item)
{
NODE *newn, *temp;
newn=(NODE*)malloc(sizeof(NODE));
newn->info=item;
newn->rlink=NULL;
if(*first==NULL)
{
newn->llink=NULL;
*first=newn;
}
else
{
temp=*first;
while(temp->rlink!=NULL)
temp=temp->rlink;
newn->llink=temp;
temp->rlink=newn;
}
}

P a g e |3
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
/* Doubly Linked List */
Delete Last
int del_last(NODE **first)
{
int item;
NODE *temp;
if(*first==NULL)
{
printf("DLL IS Emptynn");
return('0');
}
else
{
temp=*first;
if(temp->rlink==NULL)
{
item=temp->info;
*first=NULL;
free(temp);
return item;
}
else
{
while(temp->rlink!=NULL)
temp=temp->rlink;
item=temp->info;
temp->llink->rlink=NULL;
free(temp);
return item;
}
}
}

P a g e |4
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
Write A C Module To Find The Frequency Of Given Element x In A DLL.

P a g e |5
P a g e |6

nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
WAP To Search A Node With A Given Data With A DLL, If It Is Found Delete It, Otherwise Display Appropriate
Message.
int del_k(NODE **first, int k)
{
int item;
NODE *temp;
if(*first==NULL)
{
printf("DLL IS Emptynn");
return('0');
}
temp=*first;
st

if(temp->rlink==NULL && temp->info==k) //Element Found In 1 Position No Further Element Present Right To It.
{
item=temp->info;
*first=NULL;
free(temp);
return item;
}
st
if(temp->rlink!=NULL && temp->info==k) //Element Found In 1 Position Further Element Present Right To It.
{
item=temp->info;
*first=temp->rlink;
temp->rlink->llink=NULL;
free(temp);
return item;
}

}

while(temp!=NULL)
{
if(temp->info==k)
break;
temp=temp->rlink;
}
if(temp!=NULL)
{
item=temp->info;
temp->llink->rlink=temp->rlink;
if(temp->rlink!=NULL) /* If Element Found In Middle & Further Element Present Right To It */
temp->rlink->llink=temp->llink;
free(temp);
return item;
}
else
{
printf("k=%d Not Foundn", k);
return('0');
}
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
Dec 05
WAP To Perform The Following Operations On Doubly Linked List.
1)To Insert A Node To The Right Of A Given Node.
2)To Delete A Node On The Left Of A Given Node. 12 Marks.
1)To Insert A Node To The Right Of A Given Node.
void ins_x_right_to_y(NODE **first, int x, int y)
{
NODE *newn, *temp;
newn=(NODE*)malloc(sizeof(NODE));
newn->info=x;
if(*first==NULL)
printf("List Is Emptyn");
else
{
temp=*first;
if(temp->info==y && temp->rlink==NULL)
{
newn->rlink=NULL;
newn->llink=temp;
temp->rlink=newn;
}
else
{
while(temp!=NULL)
{
if(temp->info==y)
break;
temp=temp->rlink;
}
if(temp!=NULL && temp->rlink!=NULL)
{
newn->llink=temp->rlink->llink;
newn->rlink=temp->rlink;
temp->rlink->llink=newn;
temp->rlink=newn;
}
else if(temp!=NULL && temp->rlink==NULL)
{
newn->rlink=NULL;
newn->llink=temp;
temp->rlink=newn;
}
else
printf("y=%d Not Found In The Listn", y);
}
}
}

P a g e |7
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
2)To Delete A Node On The Left Of A Given Node.
int del_x_left_to_y(NODE **first, int y)
{
int item;
NODE *temp, *arc;
if(*first==NULL)
{
printf("DLL IS Emptynn");
return('0');
}
temp=*first;
while(temp!=NULL)
{
if(temp->info==y)
break;
temp=temp->rlink;
}
if(temp!=NULL && temp->llink!=NULL)
{
arc=temp->llink;
item=arc->info;
if(arc->llink!=NULL)
{
arc->llink->rlink=arc->rlink;
temp->llink=arc->llink;
}
else /* 12 13 14 if y=13, To Delete 12 */
{
temp->llink=NULL;
*first=arc->rlink;
}
free(arc);
return item;
}
else if(temp!=NULL && temp->llink==NULL)
{
printf("No Item Present Left To It So Deletion Not Possible");
return('0');
}
else
{
printf("y=%d Not Foundn");
return('0');
}
}

P a g e |8
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
To Insert A Node On The Left Of A Given Node.
void ins_x_left_to_y(NODE **first, int x, int y)
{
NODE *newn, *temp;
newn=(NODE*)malloc(sizeof(NODE));
newn->info=x;
if(*first==NULL)
printf("List Is Emptyn");
else
{
temp=*first;
if(temp->info==y)
{
newn->llink=NULL;
newn->rlink=*first;
temp->llink=newn;
*first=newn;
}
else
{
while(temp!=NULL)
{
if(temp->info==y)
break;
temp=temp->rlink;
}
if(temp!=NULL)
{
newn->llink=temp->llink;
newn->rlink=temp;
temp->llink->rlink=newn;
temp->llink=newn;
}
else
printf("y=%d Not Found In The Listn", y);
}
}
}

P a g e |9
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
To Delete A Node On The Right Of A Given Node.
int del_x_right_to_y(NODE **first, int y)
{
int item;
NODE *temp, *arc;
if(*first==NULL)
{
printf("DLL IS Emptynn");
return('0');
}
temp=*first;
while(temp!=NULL)
{
if(temp->info==y)
break;
temp=temp->rlink;
}
if(temp!=NULL && temp->rlink!=NULL)
{
arc=temp->rlink;
item=arc->info;
temp->rlink=arc->rlink;
if(arc->rlink!=NULL) /* 12,6 13, 14 if y=13 To Delete 14 It's Required */
arc->rlink->llink=arc->llink;
free(arc);
return item;
}
else if(temp!=NULL && temp->rlink==NULL)
{
printf("No Item Present Right To It, So Deletion Not Possiblen");
return('0');
}
else
{
printf("y=%d Not Foundn", y);
return('0');
}
}

P a g e | 10
nd

Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore.
Dec 06/Jan 07
WAP To Interchange The Mth And Nth Elements Of A DLL. 10Marks

P a g e | 11

Mais conteúdo relacionado

Mais procurados

linked list
linked listlinked list
linked listAbbott
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & DeletionAfaq Mansoor Khan
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationProf Ansari
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsShubham Sharma
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Adam Mukharil Bachtiar
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structureTushar Aneyrao
 
linked list using c
linked list using clinked list using c
linked list using cVenkat Reddy
 
Linked list without animation
Linked list without animationLinked list without animation
Linked list without animationLovelyn Rose
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data StructureMuhazzab Chouhadry
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked ListsJ.T.A.JONES
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)Durga Devi
 

Mais procurados (20)

linked list
linked listlinked list
linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
 
11 15 (doubly linked list)
11 15 (doubly linked list)11 15 (doubly linked list)
11 15 (doubly linked list)
 
CSE240 Doubly Linked Lists
CSE240 Doubly Linked ListsCSE240 Doubly Linked Lists
CSE240 Doubly Linked Lists
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
linked list using c
linked list using clinked list using c
linked list using c
 
Linked list without animation
Linked list without animationLinked list without animation
Linked list without animation
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 

Destaque

Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked listRoshan Chaudhary
 
05 instruction set design and architecture
05 instruction set design and architecture05 instruction set design and architecture
05 instruction set design and architectureWaqar Jamil
 
Chapter 8 - Multiplexing 9e
Chapter 8 - Multiplexing 9eChapter 8 - Multiplexing 9e
Chapter 8 - Multiplexing 9eadpeer
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listFahd Allebdi
 

Destaque (6)

Team 9
Team 9Team 9
Team 9
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked list
 
05 instruction set design and architecture
05 instruction set design and architecture05 instruction set design and architecture
05 instruction set design and architecture
 
Chapter 8 - Multiplexing 9e
Chapter 8 - Multiplexing 9eChapter 8 - Multiplexing 9e
Chapter 8 - Multiplexing 9e
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 

Semelhante a Data structure doubly linked list programs

Data structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU ExamsData structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU ExamsiCreateWorld
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular listiCreateWorld
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of listElavarasi K
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfbrijmote
 
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfBINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfARYAN20071
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 

Semelhante a Data structure doubly linked list programs (20)

Data structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU ExamsData structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU Exams
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
week-14x
week-14xweek-14x
week-14x
 
137 Lab-2.2.pdf
137 Lab-2.2.pdf137 Lab-2.2.pdf
137 Lab-2.2.pdf
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
Lab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdfLab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdf
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdf
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
linkedlist.pptx
linkedlist.pptxlinkedlist.pptx
linkedlist.pptx
 
week-16x
week-16xweek-16x
week-16x
 
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfBINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 

Último

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Último (20)

9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

Data structure doubly linked list programs

  • 1. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. /* Doubly Linked List Acts Like Stack */ #include<stdio.h> #include<stdlib.h> struct node { struct node *llink; int info; struct node *rlink; }; typedef struct node NODE; void ins_first(NODE**, int); int del_first(NODE**); void display(NODE*); int main() { NODE *first=NULL; int choice, item; for(;;) { printf("Operation Resarch On Doubly Linked Listn"); printf("Program Acts Like Stackn"); printf("1.Push OR Insert Frontn"); printf("2.Pop OR Delete Frontn"); printf("3.Displayn"); printf("4.Exitn"); printf("Enter U R Choicen"); scanf("%d", &choice); printf("nn"); switch(choice) { case 1 : printf("Enter The Item To Insertn"); scanf("%d", &item); printf("nn"); ins_first(&first, item); break; case 2 : item=del_first(&first); if(item!='0') printf("Deleted Element Is %dnn", item); break; case 3 : printf("Contents Of Stack Aren"); display(first); break; default : exit(0); } } return 1; } P a g e |1
  • 2. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. void ins_first(NODE **first, int item) { NODE *newn; newn=(NODE*)malloc(sizeof(NODE)); newn->llink=NULL; newn->info=item; if(*first==NULL) { newn->rlink=NULL; *first=newn; } else { newn->rlink=*first; newn->rlink->llink=newn; /*Hihgly IMP */ *first=newn; } } int del_first(NODE **first) { int item; NODE *temp; if(*first==NULL) { printf("Stack IS Underflownn"); return('0'); } temp=*first; item=temp->info; *first=temp->rlink; /* *first->llink=NULL Is An Error. */ free(temp); return item; } void display(NODE *first) { NODE *temp; temp=first; if(first==NULL) { printf("Stack Is Emptynn"); } else { while(temp->rlink!=NULL) { printf("%dn", temp->info); temp=temp->rlink; } printf("%dnn", temp->info); } } P a g e |2
  • 3. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. /* Doubly Linked List */ Insert Last void ins_last(NODE **first, int item) { NODE *newn, *temp; newn=(NODE*)malloc(sizeof(NODE)); newn->info=item; newn->rlink=NULL; if(*first==NULL) { newn->llink=NULL; *first=newn; } else { temp=*first; while(temp->rlink!=NULL) temp=temp->rlink; newn->llink=temp; temp->rlink=newn; } } P a g e |3
  • 4. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. /* Doubly Linked List */ Delete Last int del_last(NODE **first) { int item; NODE *temp; if(*first==NULL) { printf("DLL IS Emptynn"); return('0'); } else { temp=*first; if(temp->rlink==NULL) { item=temp->info; *first=NULL; free(temp); return item; } else { while(temp->rlink!=NULL) temp=temp->rlink; item=temp->info; temp->llink->rlink=NULL; free(temp); return item; } } } P a g e |4
  • 5. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. Write A C Module To Find The Frequency Of Given Element x In A DLL. P a g e |5
  • 6. P a g e |6 nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. WAP To Search A Node With A Given Data With A DLL, If It Is Found Delete It, Otherwise Display Appropriate Message. int del_k(NODE **first, int k) { int item; NODE *temp; if(*first==NULL) { printf("DLL IS Emptynn"); return('0'); } temp=*first; st if(temp->rlink==NULL && temp->info==k) //Element Found In 1 Position No Further Element Present Right To It. { item=temp->info; *first=NULL; free(temp); return item; } st if(temp->rlink!=NULL && temp->info==k) //Element Found In 1 Position Further Element Present Right To It. { item=temp->info; *first=temp->rlink; temp->rlink->llink=NULL; free(temp); return item; } } while(temp!=NULL) { if(temp->info==k) break; temp=temp->rlink; } if(temp!=NULL) { item=temp->info; temp->llink->rlink=temp->rlink; if(temp->rlink!=NULL) /* If Element Found In Middle & Further Element Present Right To It */ temp->rlink->llink=temp->llink; free(temp); return item; } else { printf("k=%d Not Foundn", k); return('0'); }
  • 7. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. Dec 05 WAP To Perform The Following Operations On Doubly Linked List. 1)To Insert A Node To The Right Of A Given Node. 2)To Delete A Node On The Left Of A Given Node. 12 Marks. 1)To Insert A Node To The Right Of A Given Node. void ins_x_right_to_y(NODE **first, int x, int y) { NODE *newn, *temp; newn=(NODE*)malloc(sizeof(NODE)); newn->info=x; if(*first==NULL) printf("List Is Emptyn"); else { temp=*first; if(temp->info==y && temp->rlink==NULL) { newn->rlink=NULL; newn->llink=temp; temp->rlink=newn; } else { while(temp!=NULL) { if(temp->info==y) break; temp=temp->rlink; } if(temp!=NULL && temp->rlink!=NULL) { newn->llink=temp->rlink->llink; newn->rlink=temp->rlink; temp->rlink->llink=newn; temp->rlink=newn; } else if(temp!=NULL && temp->rlink==NULL) { newn->rlink=NULL; newn->llink=temp; temp->rlink=newn; } else printf("y=%d Not Found In The Listn", y); } } } P a g e |7
  • 8. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. 2)To Delete A Node On The Left Of A Given Node. int del_x_left_to_y(NODE **first, int y) { int item; NODE *temp, *arc; if(*first==NULL) { printf("DLL IS Emptynn"); return('0'); } temp=*first; while(temp!=NULL) { if(temp->info==y) break; temp=temp->rlink; } if(temp!=NULL && temp->llink!=NULL) { arc=temp->llink; item=arc->info; if(arc->llink!=NULL) { arc->llink->rlink=arc->rlink; temp->llink=arc->llink; } else /* 12 13 14 if y=13, To Delete 12 */ { temp->llink=NULL; *first=arc->rlink; } free(arc); return item; } else if(temp!=NULL && temp->llink==NULL) { printf("No Item Present Left To It So Deletion Not Possible"); return('0'); } else { printf("y=%d Not Foundn"); return('0'); } } P a g e |8
  • 9. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. To Insert A Node On The Left Of A Given Node. void ins_x_left_to_y(NODE **first, int x, int y) { NODE *newn, *temp; newn=(NODE*)malloc(sizeof(NODE)); newn->info=x; if(*first==NULL) printf("List Is Emptyn"); else { temp=*first; if(temp->info==y) { newn->llink=NULL; newn->rlink=*first; temp->llink=newn; *first=newn; } else { while(temp!=NULL) { if(temp->info==y) break; temp=temp->rlink; } if(temp!=NULL) { newn->llink=temp->llink; newn->rlink=temp; temp->llink->rlink=newn; temp->llink=newn; } else printf("y=%d Not Found In The Listn", y); } } } P a g e |9
  • 10. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. To Delete A Node On The Right Of A Given Node. int del_x_right_to_y(NODE **first, int y) { int item; NODE *temp, *arc; if(*first==NULL) { printf("DLL IS Emptynn"); return('0'); } temp=*first; while(temp!=NULL) { if(temp->info==y) break; temp=temp->rlink; } if(temp!=NULL && temp->rlink!=NULL) { arc=temp->rlink; item=arc->info; temp->rlink=arc->rlink; if(arc->rlink!=NULL) /* 12,6 13, 14 if y=13 To Delete 14 It's Required */ arc->rlink->llink=arc->llink; free(arc); return item; } else if(temp!=NULL && temp->rlink==NULL) { printf("No Item Present Right To It, So Deletion Not Possiblen"); return('0'); } else { printf("y=%d Not Foundn", y); return('0'); } } P a g e | 10
  • 11. nd Ashoka R, 2 Sem, Maharaja Institute Of Technology Mysore. Dec 06/Jan 07 WAP To Interchange The Mth And Nth Elements Of A DLL. 10Marks P a g e | 11