Question: sourcode: //Question 6: Write a function to delete all the elements starting from the end of the list. Remember to display the list after each

sourcode: //Question 6: Write a function to delete all the elements startingfrom the end of the list. Remember to display the list aftersourcode:

//Question 6: Write a function to delete all the elements starting from the end of the list. Remember to display the list after each round.

#include

#include

#include "time.h"

struct node

{

int data;

struct node *next;

};

void print(struct node *n)

{

while(n!=NULL)

{

printf(" %d->",n->data);

n=n->next;

}

printf(" NULL ");

}

void deleteall(struct node *node)

{

while(node){

struct node *list=node;

struct node *pre=NULL;

while(list->next)

{

pre=list;

list=list->next;

}

pre->next=NULL;

print(node);

printf(" ");

}

}

int main() {

struct node *node1=(struct node *)malloc(sizeof(struct node));

struct node *node2=(struct node *)malloc(sizeof(struct node));

struct node *node3=(struct node *)malloc(sizeof(struct node));

struct node *node4=(struct node *)malloc(sizeof(struct node));

struct node *node5=(struct node *)malloc(sizeof(struct node));

srand(time(NULL));

node1->data=1+rand()%100;

node1->next=node2;

node2->data=1+rand()%100;

node2->next=node3;

node3->data=1+rand()%100;

node3->next=node4;

node4->data=1+rand()%100;

node4->next=node5;

node5->data=1+rand()%100;

node5->next=NULL;

deleteall(node1);

print(node1);

return 0;

}

expected out-put (random num) is :

25-> 31-> 27-> 100-> NULL

25-> 31-> 27-> NULL

25-> 31-> NULL

25-> NULL

NULL

6 //Question 6: Write a function to delete all the elements starting from the end of the list. Remember to display the list after each round. 7 8 #include 9 #include 10 #include "time.h" 11 struct node 12 { 13 13 int data; 14 struct node *next; 15 }; 16 void print(struct node *n) 17 { 18 while(n!=NULL) 19 { 20 printf("%d->", n->data); 21 n=n->next; 22 } 23 no printf(" NULL "); 24 } 25 void deleteall(struct node *node) 26 { 27 while(node) { 28 struct node *list=node; 29 struct node *pre=NULL; 30 while(list->next) 31 { 32 pre=list; 33 list=list->next; 34 } 35 pre->next=NULL; = Thread 1: EXC_BAD_ACCESS (code=1, address=0x8) 36 print(node); 37 printf(" "); 38 } 39} 40 int main() { 41 struct node *node 1=(struct node *) malloc(sizeof(struct node)); 42 ** struct node *node2=(struct node *) malloc(sizeof(struct node)); 43 struct node *node3=(struct node *) malloc(sizeof(struct node)); 44 struct node *node4=(struct node *) malloc(sizeof(struct node)); 45 struct node *node5=(struct node *) malloc(sizeof(struct node)); 46 srand(time(NULL)); 2 A Implicit conversion loses integer precision: "time_t' (aka 'long') to 'unsigned int' 47 node1->data=1+rand(%100; 48 node1->next=node2; madon = Thread 1: EXC_BAD_ACCESS (code=1, address=0x8) 2 & Implicit conversion loses integer precision: 'time_t' (aka 'long') to 'unsigned int' 35 pre->next=NULL; 36 print(node); 37 printf(" "); 38 } 39 } 40 int main() { 41 struct node *node1=(struct node *)malloc(sizeof(struct node)); 42 struct node *node2=(struct node *)malloc(sizeof(struct node)); 43 struct node *node3=(struct node *)malloc(sizeof(struct node)); struct node *node4=(struct node *) malloc(sizeof(struct node)); 45 struct node *hode struct node *node5=(struct node *)malloc(sizeof(struct node)); 46 srand(time(NULL)); ' 47 node1->data=1+rand()%100; ada 48 node1->next=node2; 49 node2->data=1+rand()%100; acara 50 node2->next=node3; neues 51 node3->data=1+rand()%100; 52 node 3->next=node4; 53 node4->data=1+rand()%100; 54 node4->next=node5; 55 bodo node5->data=1+rand()%100; 56 node5->next=NULL; 57 deleteall(node1); 58 print(node 1); 59 return 0; 60} 61 Line: 4 Col: 3 C ID I TO 3 8 9 > A node = (node) Ox 101129d70 > Llist = (node) Ox 101129270 > L pre = (node) NULL node6 ) Thread 1) O deleteall BO 25-> 31-> 27-> 100-> NULL 25-> 31-> 27-> NULL 25-> 31-> NULL 25-> NULL (11db) Auto Filter All Output Filter

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!