-->
当前位置:首页 > 题库

PROGRAMMING:Linked list operation - create, append and output

Luz5年前 (2021-05-10)题库424
```
Please write the function of creating linked list and outputting linked list. For the structure definition of the following data nodes,
For the linked list of the leading node, please program to complete the following functions.
struct LNode{
int data; // Data field
struct LNode *next; // Pointer field
};
struct LNode *head; // Head pointer
The input data contains several groups of commands and data. The first character in a group of data represents the command,
Next is the data required for the command.
(1) If the command is I, the function is to create an empty list, and the corresponding function is void list_ Init(head);
(2) If the command is a, followed by an integer data, the function is to append a data data to the end of the linked list,
Corresponding function: void list_ Append(head,data);
(3) If the command is C, followed by an integer n, followed by N integers, the function is to add n integers to the end of the linked list
Data can be stored by calling list_ The function of append() is implemented;
(4) If the command is p, the function traverses all the data in the output list, and the data is separated by a space
Function: void list_ Print (head), if the linked list is not established, output "list not defined!",
If the linked list is empty, output: "list is empty!".
```
###Input format:
Several groups of commands and data, many of which are written together, please pay attention to the identification.
###Output format:
Output the corresponding content according to the input command. See the output example for details.
###Input example:
```in
P I P A 100 A 200 A 300 P C 5 10 20 30 40 50 P
```
###Output example:
```out
List not defined!
List is empty!
100 200 300
100 200 300 10 20 30 40 50
```







answer:If there is no answer, please comment