HELLO! HOW DO I ADD/ INSERT NEW NODE AFTER THE NODE(DATA) OR ADDING A NODE AFTER VALUE BASED ON THIS C PROGRAM
HELLO! HOW DO I ADD/ INSERT NEW NODE AFTER THE NODE(DATA) OR ADDING A NODE AFTER VALUE BASED ON THIS C PROGRAM
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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 ME A NEW CODE FOR THE TASK PLEASE. THANK YOU
![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%2F88d4f8ff-22b7-465d-b6f0-70b853499718%2Flali5nk_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%2F88d4f8ff-22b7-465d-b6f0-70b853499718%2F8wpum0f_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 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education