PROGRAMMING:C language programming experiment 6-2 deletion of one way linked list
Based on the new one-way linked list code in experiment 6-1, the function of deleting nodes is added to delete * * all * * nodes whose data is the specified value in the linked list.
###Delete node function interface:
```
struct link * DeleteNode(struct link *head,int data);
```
-'head' is the pointer of the chain header node
-'data 'is the value of the node to be deleted.
-Function returns the pointer to the header node after deleting the corresponding node.
###Main function example:
```
#include
#include
struct link
{
int data;
struct link *next;
};
struct link *AppendNode(struct link *head,int data);
void DisplyNode(struct link *head);
void DeleteMemory(struct link *head);
struct link * DeleteNode(struct link *head,int data);
int main()
{
char c;
int data = 0;
struct link *head = NULL; /* Chain header pointer*/
while (1)
{
scanf("%d",&data);
if (data==-1)
break;
head = AppendNode(head,data);/* Add a node to the end of the linked list with head as the head pointer*/
}
DisplyNode(head); /* Display the information of each node in the current linked list*/
scanf("%d",&data);
head = DeleteNode(head,data);
DisplyNode(head); /* Display the information of each node in the current linked list*/
DeleteMemory(head); /* Free all dynamically allocated memory*/
return 0;
}
```
###Input format:
First line:
A series of values ending with '- 1' to construct a one-way linked list.
Second line:
Specified value
###Output format:
After the one-way linked list is constructed, the whole linked list is displayed.
After deleting the specified value, the whole linked list is displayed again.
###Input example:
Here is a set of inputs. For example:
```in
1 3 5 7 9 -1
five
```
###Output example:
The corresponding output is given here. For example:
```out
1->3->5->7->9
1->3->7->9
```
###Input example:
Here is a set of inputs. For example:
```in
1 3 5 3 1 -1
three
```
###Output example:
The corresponding output is given here. For example:
```out
1->3->5->3->1
1->5->1
```
answer:If there is no answer, please comment
###Delete node function interface:
```
struct link * DeleteNode(struct link *head,int data);
```
-'head' is the pointer of the chain header node
-'data 'is the value of the node to be deleted.
-Function returns the pointer to the header node after deleting the corresponding node.
###Main function example:
```
#include
#include
struct link
{
int data;
struct link *next;
};
struct link *AppendNode(struct link *head,int data);
void DisplyNode(struct link *head);
void DeleteMemory(struct link *head);
struct link * DeleteNode(struct link *head,int data);
int main()
{
char c;
int data = 0;
struct link *head = NULL; /* Chain header pointer*/
while (1)
{
scanf("%d",&data);
if (data==-1)
break;
head = AppendNode(head,data);/* Add a node to the end of the linked list with head as the head pointer*/
}
DisplyNode(head); /* Display the information of each node in the current linked list*/
scanf("%d",&data);
head = DeleteNode(head,data);
DisplyNode(head); /* Display the information of each node in the current linked list*/
DeleteMemory(head); /* Free all dynamically allocated memory*/
return 0;
}
```
###Input format:
First line:
A series of values ending with '- 1' to construct a one-way linked list.
Second line:
Specified value
###Output format:
After the one-way linked list is constructed, the whole linked list is displayed.
After deleting the specified value, the whole linked list is displayed again.
###Input example:
Here is a set of inputs. For example:
```in
1 3 5 7 9 -1
five
```
###Output example:
The corresponding output is given here. For example:
```out
1->3->5->7->9
1->3->7->9
```
###Input example:
Here is a set of inputs. For example:
```in
1 3 5 3 1 -1
three
```
###Output example:
The corresponding output is given here. For example:
```out
1->3->5->3->1
1->5->1
```
answer:If there is no answer, please comment