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
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 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);
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 2 steps

Blurred answer
Knowledge Booster
Types of trees
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education