Question
(WRITE THIS PROGRAM IN C LANGUAGE).Before I ask the question, i'm just letting you know that I asked this question before but I unfortunately the
(WRITE THIS PROGRAM IN C LANGUAGE).Before I ask the question, i'm just letting you know that I asked this question before but I unfortunately the answer was wrong, in fact, it didn't even answer my questions. So please make an effort to answer this question.
In this question, we will learn about a variant of linked list called \doubly Linked List". In addition to the ext" pointer pointing to the next node in the list, a node in a doubly linked list also contains a pointer \prev" pointing to the previous node in the list. One implementation of the doubly linked List is as follows. #include #include // Node d e f i n i t i o n f o r doubly l i n k e d l i s t typedef struct d l l n o d e { int data ; struct d l l n o d e * next ; struct d l l n o d e * prev ; } DLLnode t ; // De f ini t i on of doubly l i n k e d l i s t typedef struct { DLLnode t * head ; } DLL t ; // Creates a doubly l i n k e d l i s t DLL t * DLLCreate ( ) { DLL t * r e t = mal loc ( sizeof (DLL t ) ) ; r e t->head = NULL; return r e t ; } // Appends a DLLnode t containing the value x int o a DLL t void DLLAppend(DLL t * i n t l i s t , int x ) f // Create a DLLnode t DLLnode t * newNode = mal loc ( s izeof (DLLnode t ) ) ; newNode->data = x ; newNode->prev = NULL; newNode->next = NULL; // Point head to new node if list is empty i f ( i n t l i s t ->head == NULL) { i n t l i s t ->head = newNode ; return ; } DLLnode t * temp =i n t l i s t ->head ; while ( temp->next != NULL) { temp = temp->next ; // Go To last Node } temp->next = newNode ; newNode->prev = temp ; } // Prints the elements of a doubly l i n k e d l i s t void DLLPrint (DLL t * i n t l i s t ) f DLLnode t * temp = i n t l i s t ->head ; while ( temp != NULL) { p r i n t f ( "%d " , temp->data ) ; temp = temp->next ; } p r i n t f ( " " ) ; } Part a) Based on the doubly linked list implementation given above, implement a func- tion called \DLLReverse" to reverse a list. For example, if a doubly linked list originally contains the list f4, 5, 7, 7, 9g, after calling DLLReverse, the list would become f9, 7, 7, 5, 4g. The function prototype is given below. // Reverses a DLL t void DLLReverse (DLL t * i n t l i s t ) f } Part b) Implement a function called \DLLRemove" to remove any node at a specied index \ind". Just as with C++ arrays, the rst element of the list should have an index of 0. Starting at 0, indices go up to one less than the length of the list. Your DLLRemove function should give the following message if the user passes in an invalid index: \Warning: Invalid index!" No other operations should be done if the index is invalid. The function prototype is given below. // Removes the element at index ind f o r a DLL t , and // warns the user i f the index i s i n v a l i d void DLLRemove(DLL t * i n t l i s t , int ind ) {
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started