HOW DO I ADD/ INSERT NEW NODE AFTER THE NODE(DATA) OR ADDING A NODE AFTER VALUE BASED ON THIS C PROGRAM
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...
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
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);](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe37b5fcd-dc1c-46ad-9cdd-200d4806c7f1%2Ff183e759-ddf1-4453-9f4a-5188c9976631%2Fn4fk8wh_processed.png&w=3840&q=75)
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe37b5fcd-dc1c-46ad-9cdd-200d4806c7f1%2Ff183e759-ddf1-4453-9f4a-5188c9976631%2Fjsqfc1f_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
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](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY