SlideShare a Scribd company logo
1 of 9
Download to read offline
Solution
:
#include
#include
#include
//-------------------------------------------------
struct node
{
int data;
struct node *next;
}*start=NULL;
//------------------------------------------------------------
void creat()
{
char ch;
do
{
struct node *new_node,*current;
new_node=(struct node *)malloc(sizeof(struct node));
printf("nEnter the data : ");
scanf("%d",&new_node->data);
new_node->next=NULL;
if(start==NULL)
{
start=new_node;
current=new_node;
}
else
{
current->next=new_node;
current=new_node;
}
printf("nDo you want to creat another : ");
ch=getche();
}while(ch!='n');
}
//------------------------------------------------------------------
void display()
{
struct node *new_node;
printf("The Linked List : n");
new_node=start;
while(new_node!=NULL)
{
printf("%d--->",new_node->data);
new_node=new_node->next;
}
printf("NULL");
}
//----------------------------------------------------
void main()
{
create();
display();
}
//----------------------------------------------------
Output :
#include
#include
#include
#include
struct node {
int data;
int key;
struct node *next;
struct node *prev;
};
//this link always point to first Link
struct node *head = NULL;
//this link always point to last Link
struct node *last = NULL;
struct node *current = NULL;
//is list empty
bool isEmpty(){
return head == NULL;
}
int length(){
int length = 0;
struct node *current;
for(current = head; current != NULL; current = current->next){
length++;
}
return length;
}
//display the list in from first to last
void displayForward(){
//start from the beginning
struct node *ptr = head;
//navigate till the end of the list
printf(" [ ");
while(ptr != NULL){
printf("(%d,%d) ",ptr->key,ptr->data);
ptr = ptr->next;
}
printf(" ]");
}
//display the list from last to first
void displayBackward(){
//start from the last
struct node *ptr = last;
//navigate till the start of the list
printf(" [ ");
while(ptr != NULL){
//print data
printf("(%d,%d) ",ptr->key,ptr->data);
//move to next item
ptr = ptr ->prev;
printf(" ");
}
printf(" ]");
}
//insert link at the first location
void insertFirst(int key, int data){
//create a link
struct node *link = (struct node*) malloc(sizeof(struct node));
link->key = key;
link->data = data;
if(isEmpty()){
//make it the last link
last = link;
}else {
//update first prev link
head->prev = link;
}
//point it to old first link
link->next = head;
//point first to new first link
head = link;
}
//insert link at the last location
void insertLast(int key, int data){
//create a link
struct node *link = (struct node*) malloc(sizeof(struct node));
link->key = key;
link->data = data;
if(isEmpty()){
//make it the last link
last = link;
}else {
//make link a new last link
last->next = link;
//mark old last node as prev of new link
link->prev = last;
}
//point last to new last node
last = link;
}
//delete first item
struct node* deleteFirst(){
//save reference to first link
struct node *tempLink = head;
//if only one link
if(head->next == NULL){
last = NULL;
}else {
head->next->prev = NULL;
}
head = head->next;
//return the deleted link
return tempLink;
}
//delete link at the last location
struct node* deleteLast(){
//save reference to last link
struct node *tempLink = last;
//if only one link
if(head->next == NULL){
head = NULL;
}else {
last->prev->next = NULL;
}
last = last->prev;
//return the deleted link
return tempLink;
}
//delete a link with given key
struct node* delete(int key){
//start from the first link
struct node* current = head;
struct node* previous = NULL;
//if list is empty
if(head == NULL){
return NULL;
}
//navigate through list
while(current->key != key){
//if it is last node
if(current->next == NULL){
return NULL;
}else {
//store reference to current link
previous = current;
//move to next link
current = current->next;
}
}
//found a match, update the link
if(current == head) {
//change first to point to next link
head = head->next;
}else {
//bypass the current link
current->prev->next = current->next;
}
if(current == last){
//change last to point to prev link
last = current->prev;
}else {
current->next->prev = current->prev;
}
return current;
}
bool insertAfter(int key, int newKey, int data){
//start from the first link
struct node *current = head;
//if list is empty
if(head == NULL){
return false;
}
//navigate through list
while(current->key != key){
//if it is last node
if(current->next == NULL){
return false;
}else {
//move to next link
current = current->next;
}
}
//create a link
struct node *newLink = (struct node*) malloc(sizeof(struct node));
newLink->key = key;
newLink->data = data;
if(current == last) {
newLink->next = NULL;
last = newLink;
}else {
newLink->next = current->next;
current->next->prev = newLink;
}
newLink->prev = current;
current->next = newLink;
return true;
}
main() {
insertFirst(1,10);
insertFirst(2,20);
insertFirst(3,30);
insertFirst(4,1);
insertFirst(5,40);
insertFirst(6,56);
printf(" List (First to Last): ");
displayForward();
printf(" ");
printf(" List (Last to first): ");
displayBackward();
printf(" List , after deleting first record: ");
deleteFirst();
displayForward();
printf(" List , after deleting last record: ");
deleteLast();
displayForward();
printf(" List , insert after key(4) : ");
insertAfter(4,7, 13);
displayForward();
printf(" List , after delete key(4) : ");
delete(4);
displayForward();
}
Output:
The

More Related Content

Similar to Solution#includestdio.h#includeconio.h#includealloc.h.pdf

Implement a priority queue using a doublyLinked-cpp where the node wit.pdf
Implement a priority queue using a doublyLinked-cpp where the node wit.pdfImplement a priority queue using a doublyLinked-cpp where the node wit.pdf
Implement a priority queue using a doublyLinked-cpp where the node wit.pdfBlakeY8lBucklandh
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdfshanki7
 
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
 
operating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdfoperating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdfaquacareser
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxtienlivick
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked listSourav Gayen
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxVeerannaKotagi1
 
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdfANJALIENTERPRISES1
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfamitbagga0808
 
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
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docxajoy21
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdfharihelectronicspune
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docxacarolyn
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfanton291
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdflakshmijewellery
 

Similar to Solution#includestdio.h#includeconio.h#includealloc.h.pdf (20)

Implement a priority queue using a doublyLinked-cpp where the node wit.pdf
Implement a priority queue using a doublyLinked-cpp where the node wit.pdfImplement a priority queue using a doublyLinked-cpp where the node wit.pdf
Implement a priority queue using a doublyLinked-cpp where the node wit.pdf
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
 
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
 
operating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdfoperating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docx
 
Linked list
Linked listLinked list
Linked list
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docx
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.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
 
Linked lists
Linked listsLinked lists
Linked lists
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
 

More from poddaranand1

S02 is the only polar molecule as the other molec.pdf
                     S02 is the only polar molecule as the other molec.pdf                     S02 is the only polar molecule as the other molec.pdf
S02 is the only polar molecule as the other molec.pdfpoddaranand1
 
Solve for the weight of all three, S1, O3, He1.pdf
                     Solve for the weight of all three, S1, O3, He1.pdf                     Solve for the weight of all three, S1, O3, He1.pdf
Solve for the weight of all three, S1, O3, He1.pdfpoddaranand1
 
Phenol is the strongest acid because Phenoxide io.pdf
                     Phenol is the strongest acid because Phenoxide io.pdf                     Phenol is the strongest acid because Phenoxide io.pdf
Phenol is the strongest acid because Phenoxide io.pdfpoddaranand1
 
homogeneous describes a solutionmixture that is .pdf
                     homogeneous describes a solutionmixture that is .pdf                     homogeneous describes a solutionmixture that is .pdf
homogeneous describes a solutionmixture that is .pdfpoddaranand1
 
Propanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdf
Propanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdfPropanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdf
Propanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdfpoddaranand1
 
From an ESR study of VOCl2 dissolved in toluene c.pdf
                     From an ESR study of VOCl2 dissolved in toluene c.pdf                     From an ESR study of VOCl2 dissolved in toluene c.pdf
From an ESR study of VOCl2 dissolved in toluene c.pdfpoddaranand1
 
Wire framing is an important step in any screen design process. It i.pdf
Wire framing is an important step in any screen design process. It i.pdfWire framing is an important step in any screen design process. It i.pdf
Wire framing is an important step in any screen design process. It i.pdfpoddaranand1
 
The phase it is in is anaphase, chromosomes start to move toward the.pdf
The phase it is in is anaphase, chromosomes start to move toward the.pdfThe phase it is in is anaphase, chromosomes start to move toward the.pdf
The phase it is in is anaphase, chromosomes start to move toward the.pdfpoddaranand1
 
The normal heartbeat is 60-72 per minute. The pumping of the blood f.pdf
The normal heartbeat is 60-72 per minute. The pumping of the blood f.pdfThe normal heartbeat is 60-72 per minute. The pumping of the blood f.pdf
The normal heartbeat is 60-72 per minute. The pumping of the blood f.pdfpoddaranand1
 
the acronym of CIA is Central Intelligence Agency — it is an indep.pdf
the acronym of CIA is Central Intelligence Agency — it is an indep.pdfthe acronym of CIA is Central Intelligence Agency — it is an indep.pdf
the acronym of CIA is Central Intelligence Agency — it is an indep.pdfpoddaranand1
 
reaction of zirconium with water in water reactors releases hydrogen.pdf
reaction of zirconium with water in water reactors releases hydrogen.pdfreaction of zirconium with water in water reactors releases hydrogen.pdf
reaction of zirconium with water in water reactors releases hydrogen.pdfpoddaranand1
 
In the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdf
In the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdfIn the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdf
In the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdfpoddaranand1
 
Inadequacy in Hartee theory1) It does not contain the exchange ter.pdf
Inadequacy in Hartee theory1) It does not contain the exchange ter.pdfInadequacy in Hartee theory1) It does not contain the exchange ter.pdf
Inadequacy in Hartee theory1) It does not contain the exchange ter.pdfpoddaranand1
 
Flash helps prevent more flash from forming.This also forces the m.pdf
Flash helps prevent more flash from forming.This also forces the m.pdfFlash helps prevent more flash from forming.This also forces the m.pdf
Flash helps prevent more flash from forming.This also forces the m.pdfpoddaranand1
 
Convolutional Neural Networks square measure terribly kind of like n.pdf
Convolutional Neural Networks square measure terribly kind of like n.pdfConvolutional Neural Networks square measure terribly kind of like n.pdf
Convolutional Neural Networks square measure terribly kind of like n.pdfpoddaranand1
 
AnswerProject’s required return of 12 will be used as discount ra.pdf
AnswerProject’s required return of 12 will be used as discount ra.pdfAnswerProject’s required return of 12 will be used as discount ra.pdf
AnswerProject’s required return of 12 will be used as discount ra.pdfpoddaranand1
 
A. Angelman syndrome is rare genetic disorder characterized by learn.pdf
A. Angelman syndrome is rare genetic disorder characterized by learn.pdfA. Angelman syndrome is rare genetic disorder characterized by learn.pdf
A. Angelman syndrome is rare genetic disorder characterized by learn.pdfpoddaranand1
 
1)increases decreases2)increaseFor others just use the p.pdf
1)increases decreases2)increaseFor others just use the p.pdf1)increases decreases2)increaseFor others just use the p.pdf
1)increases decreases2)increaseFor others just use the p.pdfpoddaranand1
 
2ethyl 1penteneSolution2ethyl 1pentene.pdf
2ethyl 1penteneSolution2ethyl 1pentene.pdf2ethyl 1penteneSolution2ethyl 1pentene.pdf
2ethyl 1penteneSolution2ethyl 1pentene.pdfpoddaranand1
 

More from poddaranand1 (20)

S02 is the only polar molecule as the other molec.pdf
                     S02 is the only polar molecule as the other molec.pdf                     S02 is the only polar molecule as the other molec.pdf
S02 is the only polar molecule as the other molec.pdf
 
Solve for the weight of all three, S1, O3, He1.pdf
                     Solve for the weight of all three, S1, O3, He1.pdf                     Solve for the weight of all three, S1, O3, He1.pdf
Solve for the weight of all three, S1, O3, He1.pdf
 
Phenol is the strongest acid because Phenoxide io.pdf
                     Phenol is the strongest acid because Phenoxide io.pdf                     Phenol is the strongest acid because Phenoxide io.pdf
Phenol is the strongest acid because Phenoxide io.pdf
 
homogeneous describes a solutionmixture that is .pdf
                     homogeneous describes a solutionmixture that is .pdf                     homogeneous describes a solutionmixture that is .pdf
homogeneous describes a solutionmixture that is .pdf
 
Propanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdf
Propanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdfPropanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdf
Propanol has molecular formula CH3-CH2-CH2-OH.It is a polar organi.pdf
 
From an ESR study of VOCl2 dissolved in toluene c.pdf
                     From an ESR study of VOCl2 dissolved in toluene c.pdf                     From an ESR study of VOCl2 dissolved in toluene c.pdf
From an ESR study of VOCl2 dissolved in toluene c.pdf
 
Wire framing is an important step in any screen design process. It i.pdf
Wire framing is an important step in any screen design process. It i.pdfWire framing is an important step in any screen design process. It i.pdf
Wire framing is an important step in any screen design process. It i.pdf
 
The phase it is in is anaphase, chromosomes start to move toward the.pdf
The phase it is in is anaphase, chromosomes start to move toward the.pdfThe phase it is in is anaphase, chromosomes start to move toward the.pdf
The phase it is in is anaphase, chromosomes start to move toward the.pdf
 
The normal heartbeat is 60-72 per minute. The pumping of the blood f.pdf
The normal heartbeat is 60-72 per minute. The pumping of the blood f.pdfThe normal heartbeat is 60-72 per minute. The pumping of the blood f.pdf
The normal heartbeat is 60-72 per minute. The pumping of the blood f.pdf
 
the acronym of CIA is Central Intelligence Agency — it is an indep.pdf
the acronym of CIA is Central Intelligence Agency — it is an indep.pdfthe acronym of CIA is Central Intelligence Agency — it is an indep.pdf
the acronym of CIA is Central Intelligence Agency — it is an indep.pdf
 
reaction of zirconium with water in water reactors releases hydrogen.pdf
reaction of zirconium with water in water reactors releases hydrogen.pdfreaction of zirconium with water in water reactors releases hydrogen.pdf
reaction of zirconium with water in water reactors releases hydrogen.pdf
 
D) IV So.pdf
                     D) IV                                      So.pdf                     D) IV                                      So.pdf
D) IV So.pdf
 
In the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdf
In the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdfIn the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdf
In the addition of HX to an unsymmetrical alkene, the H atom bonds t.pdf
 
Inadequacy in Hartee theory1) It does not contain the exchange ter.pdf
Inadequacy in Hartee theory1) It does not contain the exchange ter.pdfInadequacy in Hartee theory1) It does not contain the exchange ter.pdf
Inadequacy in Hartee theory1) It does not contain the exchange ter.pdf
 
Flash helps prevent more flash from forming.This also forces the m.pdf
Flash helps prevent more flash from forming.This also forces the m.pdfFlash helps prevent more flash from forming.This also forces the m.pdf
Flash helps prevent more flash from forming.This also forces the m.pdf
 
Convolutional Neural Networks square measure terribly kind of like n.pdf
Convolutional Neural Networks square measure terribly kind of like n.pdfConvolutional Neural Networks square measure terribly kind of like n.pdf
Convolutional Neural Networks square measure terribly kind of like n.pdf
 
AnswerProject’s required return of 12 will be used as discount ra.pdf
AnswerProject’s required return of 12 will be used as discount ra.pdfAnswerProject’s required return of 12 will be used as discount ra.pdf
AnswerProject’s required return of 12 will be used as discount ra.pdf
 
A. Angelman syndrome is rare genetic disorder characterized by learn.pdf
A. Angelman syndrome is rare genetic disorder characterized by learn.pdfA. Angelman syndrome is rare genetic disorder characterized by learn.pdf
A. Angelman syndrome is rare genetic disorder characterized by learn.pdf
 
1)increases decreases2)increaseFor others just use the p.pdf
1)increases decreases2)increaseFor others just use the p.pdf1)increases decreases2)increaseFor others just use the p.pdf
1)increases decreases2)increaseFor others just use the p.pdf
 
2ethyl 1penteneSolution2ethyl 1pentene.pdf
2ethyl 1penteneSolution2ethyl 1pentene.pdf2ethyl 1penteneSolution2ethyl 1pentene.pdf
2ethyl 1penteneSolution2ethyl 1pentene.pdf
 

Recently uploaded

21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 

Recently uploaded (20)

21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Solution#includestdio.h#includeconio.h#includealloc.h.pdf

  • 1. Solution : #include #include #include //------------------------------------------------- struct node { int data; struct node *next; }*start=NULL; //------------------------------------------------------------ void creat() { char ch; do { struct node *new_node,*current; new_node=(struct node *)malloc(sizeof(struct node)); printf("nEnter the data : "); scanf("%d",&new_node->data); new_node->next=NULL; if(start==NULL) { start=new_node; current=new_node; } else { current->next=new_node; current=new_node; } printf("nDo you want to creat another : "); ch=getche(); }while(ch!='n'); }
  • 2. //------------------------------------------------------------------ void display() { struct node *new_node; printf("The Linked List : n"); new_node=start; while(new_node!=NULL) { printf("%d--->",new_node->data); new_node=new_node->next; } printf("NULL"); } //---------------------------------------------------- void main() { create(); display(); } //---------------------------------------------------- Output : #include #include #include #include struct node { int data; int key; struct node *next; struct node *prev; }; //this link always point to first Link struct node *head = NULL; //this link always point to last Link struct node *last = NULL;
  • 3. struct node *current = NULL; //is list empty bool isEmpty(){ return head == NULL; } int length(){ int length = 0; struct node *current; for(current = head; current != NULL; current = current->next){ length++; } return length; } //display the list in from first to last void displayForward(){ //start from the beginning struct node *ptr = head; //navigate till the end of the list printf(" [ "); while(ptr != NULL){ printf("(%d,%d) ",ptr->key,ptr->data); ptr = ptr->next; } printf(" ]"); } //display the list from last to first void displayBackward(){ //start from the last struct node *ptr = last; //navigate till the start of the list
  • 4. printf(" [ "); while(ptr != NULL){ //print data printf("(%d,%d) ",ptr->key,ptr->data); //move to next item ptr = ptr ->prev; printf(" "); } printf(" ]"); } //insert link at the first location void insertFirst(int key, int data){ //create a link struct node *link = (struct node*) malloc(sizeof(struct node)); link->key = key; link->data = data; if(isEmpty()){ //make it the last link last = link; }else { //update first prev link head->prev = link; } //point it to old first link link->next = head; //point first to new first link head = link; } //insert link at the last location void insertLast(int key, int data){
  • 5. //create a link struct node *link = (struct node*) malloc(sizeof(struct node)); link->key = key; link->data = data; if(isEmpty()){ //make it the last link last = link; }else { //make link a new last link last->next = link; //mark old last node as prev of new link link->prev = last; } //point last to new last node last = link; } //delete first item struct node* deleteFirst(){ //save reference to first link struct node *tempLink = head; //if only one link if(head->next == NULL){ last = NULL; }else { head->next->prev = NULL; } head = head->next; //return the deleted link return tempLink; } //delete link at the last location struct node* deleteLast(){ //save reference to last link
  • 6. struct node *tempLink = last; //if only one link if(head->next == NULL){ head = NULL; }else { last->prev->next = NULL; } last = last->prev; //return the deleted link return tempLink; } //delete a link with given key struct node* delete(int key){ //start from the first link struct node* current = head; struct node* previous = NULL; //if list is empty if(head == NULL){ return NULL; } //navigate through list while(current->key != key){ //if it is last node if(current->next == NULL){ return NULL; }else { //store reference to current link previous = current; //move to next link current = current->next;
  • 7. } } //found a match, update the link if(current == head) { //change first to point to next link head = head->next; }else { //bypass the current link current->prev->next = current->next; } if(current == last){ //change last to point to prev link last = current->prev; }else { current->next->prev = current->prev; } return current; } bool insertAfter(int key, int newKey, int data){ //start from the first link struct node *current = head; //if list is empty if(head == NULL){ return false; } //navigate through list while(current->key != key){ //if it is last node if(current->next == NULL){ return false; }else { //move to next link current = current->next;
  • 8. } } //create a link struct node *newLink = (struct node*) malloc(sizeof(struct node)); newLink->key = key; newLink->data = data; if(current == last) { newLink->next = NULL; last = newLink; }else { newLink->next = current->next; current->next->prev = newLink; } newLink->prev = current; current->next = newLink; return true; } main() { insertFirst(1,10); insertFirst(2,20); insertFirst(3,30); insertFirst(4,1); insertFirst(5,40); insertFirst(6,56); printf(" List (First to Last): "); displayForward(); printf(" "); printf(" List (Last to first): "); displayBackward(); printf(" List , after deleting first record: "); deleteFirst(); displayForward(); printf(" List , after deleting last record: ");
  • 9. deleteLast(); displayForward(); printf(" List , insert after key(4) : "); insertAfter(4,7, 13); displayForward(); printf(" List , after delete key(4) : "); delete(4); displayForward(); } Output: The