SlideShare a Scribd company logo
1 of 3
Below is a depiction of a doubly-linked list implementation of the bag ADT with two sentinels -
one at the head and one at the tail. Strict DLink { TYPE value; strict DLink * next; struct DLink
* prev;}; strict linked List { int size; struct DLink *frontSentinel; struct DLink *backSentinel;};
Write a function that at first reverses the list and then prints the values of the links in the list from
front to back. Don't redirect to any other function. You must use assertions if necessary.
Solution
/* Program to reverse a doubly linked list */
#include <stdio.h>
#include <stdlib.h>
/* a node of the doubly linked list */
struct node
{
int data;
struct node *n;
struct node *pr;
};
/* Function to reverse a Doubly Linked List */
void reverse(struct node **head_r)
{
struct node *t = NULL;
struct node *cur = *head_r;
/* swap next and prev for all nodes of
doubly linked list */
while (cur != NULL)
{
t = cur->pr;
cur->pr = cur->n;
cur->n = t;
cur = cur->pr;
}
/* Before changing head, check for the cases like empty
list and list with only one node */
if(t != NULL )
*head_r = t->pr;
}
/* UTILITY FUNCTIONS */
/* Function to insert a node at the beginging of the Doubly Linked List */
void push(struct node** head_r, int new_data)
{
/* allocate node */
struct node* n_node =
(struct node*) malloc(sizeof(struct node));
/* put in the data */
n_node->data = n_data;
/* since we are adding at the begining,
prev is always NULL */
n_node->pr = NULL;
/* link the old list off the new node */
n_node->n = (*head_r);
/* change prev of head node to new node */
if((*head_r) != NULL)
(*head_r)->pr = n_node ;
/* move the head to point to the new node */
(*head_r) = n_node;
}
/* Function to print nodes in a given doubly linked list
This function is same as printList() of singly linked lsit */
void printList(struct node *node)
{
while(node!=NULL)
{
printf("%d ", node->data);
node = node->next;
}
}
/* Drier program to test above functions*/
int main()
{
/* Start with the empty list */
struct node* head = NULL;
/* Let us create a sorted linked list to test the functions
Created linked list will be 10->8->4->2 */
push(&head, 2);
push(&head, 4);
push(&head, 8);
push(&head, 10);
printf(" Original Linked list ");
printList(head);
/* Reverse doubly linked list */
reverse(&head);
printf(" Reversed Linked list ");
printList(head);
getchar();
}

More Related Content

Similar to Below is a depiction of a doubly-linked list implementation of the bag.docx

Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfsauravmanwanicp
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfthangarajarivukadal
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
 
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
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfsales98
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfangelfragranc
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
Write java program using linked list to get integer from user and.docx
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docxajoy21
 
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
 
Write a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdfWrite a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdfkavithaarp
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfferoz544
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdfshanki7
 
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++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxMatthPYNashd
 

Similar to Below is a depiction of a doubly-linked list implementation of the bag.docx (20)

Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdf
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
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
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdf
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
Write java program using linked list to get integer from user and.docx
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docx
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
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
 
Write a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdfWrite a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
 
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
 
C++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docxC++ please put everthing after you answer it- thanks Complete the stub.docx
C++ please put everthing after you answer it- thanks Complete the stub.docx
 

More from gilliandunce53776

Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxBullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxgilliandunce53776
 
c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxgilliandunce53776
 
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxBusiness Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxgilliandunce53776
 
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxBrief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxgilliandunce53776
 
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxBriefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxgilliandunce53776
 
Brief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxBrief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxgilliandunce53776
 
Both Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxBoth Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxgilliandunce53776
 
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxBrand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxgilliandunce53776
 
Betty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxBetty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxgilliandunce53776
 
Beyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxBeyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxgilliandunce53776
 
Below is accounting information for Cascade Company for 2013- What we.docx
Below is accounting information for Cascade Company for 2013-  What we.docxBelow is accounting information for Cascade Company for 2013-  What we.docx
Below is accounting information for Cascade Company for 2013- What we.docxgilliandunce53776
 
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxcaiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxgilliandunce53776
 
C++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxC++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxgilliandunce53776
 
C++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docxC++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docxgilliandunce53776
 

More from gilliandunce53776 (14)

Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxBullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
 
c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docx
 
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxBusiness Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
 
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxBrief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
 
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxBriefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
 
Brief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxBrief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docx
 
Both Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxBoth Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docx
 
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxBrand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
 
Betty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxBetty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docx
 
Beyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxBeyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docx
 
Below is accounting information for Cascade Company for 2013- What we.docx
Below is accounting information for Cascade Company for 2013-  What we.docxBelow is accounting information for Cascade Company for 2013-  What we.docx
Below is accounting information for Cascade Company for 2013- What we.docx
 
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxcaiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
 
C++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxC++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docx
 
C++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docxC++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docx
 

Recently uploaded

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
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
 

Recently uploaded (20)

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
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
 

Below is a depiction of a doubly-linked list implementation of the bag.docx

  • 1. Below is a depiction of a doubly-linked list implementation of the bag ADT with two sentinels - one at the head and one at the tail. Strict DLink { TYPE value; strict DLink * next; struct DLink * prev;}; strict linked List { int size; struct DLink *frontSentinel; struct DLink *backSentinel;}; Write a function that at first reverses the list and then prints the values of the links in the list from front to back. Don't redirect to any other function. You must use assertions if necessary. Solution /* Program to reverse a doubly linked list */ #include <stdio.h> #include <stdlib.h> /* a node of the doubly linked list */ struct node { int data; struct node *n; struct node *pr; }; /* Function to reverse a Doubly Linked List */ void reverse(struct node **head_r) { struct node *t = NULL; struct node *cur = *head_r; /* swap next and prev for all nodes of doubly linked list */ while (cur != NULL) { t = cur->pr; cur->pr = cur->n; cur->n = t; cur = cur->pr; }
  • 2. /* Before changing head, check for the cases like empty list and list with only one node */ if(t != NULL ) *head_r = t->pr; } /* UTILITY FUNCTIONS */ /* Function to insert a node at the beginging of the Doubly Linked List */ void push(struct node** head_r, int new_data) { /* allocate node */ struct node* n_node = (struct node*) malloc(sizeof(struct node)); /* put in the data */ n_node->data = n_data; /* since we are adding at the begining, prev is always NULL */ n_node->pr = NULL; /* link the old list off the new node */ n_node->n = (*head_r); /* change prev of head node to new node */ if((*head_r) != NULL) (*head_r)->pr = n_node ; /* move the head to point to the new node */ (*head_r) = n_node; } /* Function to print nodes in a given doubly linked list This function is same as printList() of singly linked lsit */ void printList(struct node *node) { while(node!=NULL) { printf("%d ", node->data); node = node->next; } } /* Drier program to test above functions*/
  • 3. int main() { /* Start with the empty list */ struct node* head = NULL; /* Let us create a sorted linked list to test the functions Created linked list will be 10->8->4->2 */ push(&head, 2); push(&head, 4); push(&head, 8); push(&head, 10); printf(" Original Linked list "); printList(head); /* Reverse doubly linked list */ reverse(&head); printf(" Reversed Linked list "); printList(head); getchar(); }