Question: Write an improved version of the code to do the following: Change the linked list to be doubly - linked: each node X has a
Write an improved version of the code to do the following:
Change the linked list to be doublylinked: each node X has a pointer to the node
after node X and to the node before node X A pointer root points to the head of
the queue and a pointer end points to the tail of the queue.
Every new line read from the file is stored in a new node which is inserted at the
head of the linked list as in the original code Pointer root points to the node with
the last line read so far.
#include
#include
#include
struct node
char info;
struct node next;
;
int main int argc, char argv
FILE fp;
char line;
struct node root;
struct node newnode;
struct node pq;
if argc
printf Error no file provided.
;
return;
fp fopen argvr ;
if fp NULL
printf Error file not found.
;
return;
root NULL;
while fgets line fp NULL
newnode malloc sizeof struct node ;
strcpy newnode info, line;
newnode next root;
root newnode;
for p root; p NULL; p p next
printf s pinfo ;
for p root; p NULL; p q
q p next;
freep;
return;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
