HOW DO I ADD/ INSERT NEW NODE AFTER THE NODE(DATA) OR ADDING A NODE AFTER VALUE BASED ON THIS C PROGRAM

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

HELLO! HOW DO I ADD/ INSERT NEW NODE AFTER THE NODE(DATA) OR ADDING A NODE AFTER VALUE BASED ON THIS C PROGRAM

 

WRITE A NEW C CODE FOR THE TASK BASED ON THIS CODE

Adding of New Node at the Start.c
Hinclude <stdio.h>
Hinclude <stdlib.h>
struct node {
int data;
struct node *next;
}*head;
void creation (int n);
add (int data);
void display();
10
11
12
int main()
13
14
15
16
int n, data;
printf("\n***** This program shows the List of your Daily Expenses *****\n");
printt("\nHow many expenses do you want to input? ");
scant ("%d", 8n);
creation(n);
17
18
19
20
21
22
printt("\n" "\tList of Daily Expenses \n");
display();
23
24
printf("\n\nEnter the amount you want to insert at the start of the list: PHP ");
scanf ("zd", adata);
add (data);
25
26
27
28
29
30
printf("\n" "\tUpdated List of Daily Expenses \n");
display();
31
32
return e;
33
34
35
36
void creation (int n)
struct node *newNode, *temp;
int data, i;
37
38
39
40
head = (struct node *)malloc(sizeof(struct node));
if(head == NULL)
41
I printt("Unable to allocate memory.");
44
45
else
46
printf("\nEnter the amount for your daily expenses no. 1: PHP ");
scant ("sa", sdata);
47
48
49
se
51
52
head ->data = data;
head->next = NULL;
temp = head;
53
for (i=2; ic=n; i++)
newNode = (struct node *)malloc (sizeof (struct node));
if(newNode == NULL)
58
59
6e
61
print+("Unable to allocate memory.");
break;
62
else
printt("Enter the amount for your daily expenses no. Xd: PHP ", 1);
Transcribed Image Text:Adding of New Node at the Start.c Hinclude <stdio.h> Hinclude <stdlib.h> struct node { int data; struct node *next; }*head; void creation (int n); add (int data); void display(); 10 11 12 int main() 13 14 15 16 int n, data; printf("\n***** This program shows the List of your Daily Expenses *****\n"); printt("\nHow many expenses do you want to input? "); scant ("%d", 8n); creation(n); 17 18 19 20 21 22 printt("\n" "\tList of Daily Expenses \n"); display(); 23 24 printf("\n\nEnter the amount you want to insert at the start of the list: PHP "); scanf ("zd", adata); add (data); 25 26 27 28 29 30 printf("\n" "\tUpdated List of Daily Expenses \n"); display(); 31 32 return e; 33 34 35 36 void creation (int n) struct node *newNode, *temp; int data, i; 37 38 39 40 head = (struct node *)malloc(sizeof(struct node)); if(head == NULL) 41 I printt("Unable to allocate memory."); 44 45 else 46 printf("\nEnter the amount for your daily expenses no. 1: PHP "); scant ("sa", sdata); 47 48 49 se 51 52 head ->data = data; head->next = NULL; temp = head; 53 for (i=2; ic=n; i++) newNode = (struct node *)malloc (sizeof (struct node)); if(newNode == NULL) 58 59 6e 61 print+("Unable to allocate memory."); break; 62 else printt("Enter the amount for your daily expenses no. Xd: PHP ", 1);
printf("Enter the amount for your daily expenses no. %d: PHP ", 1);
scanf ("a", 8data);
64
65
66
newNode - >data = data;
67
68
newNode ->next = NULL;
%3D
69
70
temp ->next = newNode;
temp = temp->next;
71
72
73
74
75
76
void add(int data)
77
78
struct node *neNode;
newNode = (struct node*)malloc (sizeof (struct node));
79
se
81
82
if(newNode - NULL)
83
84
printt("Unable to allocate memory.");
else
85
86
87
88
newNode - >data = data;
newNode - >next = head;
head = newNode;
89
se
91
92
void display()
93
94
95
struct node *temp ;
96
97
98
if(head == NULL)
99
100
I printf("The Daily Expenses List is empty.");
else
101
102
103
104
temp = head;
while(temp i= NULL)
105
106
printt("\tDaily Expenses = PHP Xa\n", temp->data);
temp = temp->next;
107
108
109
11e
Transcribed Image Text:printf("Enter the amount for your daily expenses no. %d: PHP ", 1); scanf ("a", 8data); 64 65 66 newNode - >data = data; 67 68 newNode ->next = NULL; %3D 69 70 temp ->next = newNode; temp = temp->next; 71 72 73 74 75 76 void add(int data) 77 78 struct node *neNode; newNode = (struct node*)malloc (sizeof (struct node)); 79 se 81 82 if(newNode - NULL) 83 84 printt("Unable to allocate memory."); else 85 86 87 88 newNode - >data = data; newNode - >next = head; head = newNode; 89 se 91 92 void display() 93 94 95 struct node *temp ; 96 97 98 if(head == NULL) 99 100 I printf("The Daily Expenses List is empty."); else 101 102 103 104 temp = head; while(temp i= NULL) 105 106 printt("\tDaily Expenses = PHP Xa\n", temp->data); temp = temp->next; 107 108 109 11e
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY