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

PROGRAMMING:Linked list operation - insert, find and delete

Luz5年前 (2021-05-10)题库489
```
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!".
```
The above is the content of the previous topic. On this basis, the following functions are added:
```
(5) If the command is n, followed by an integer n and D, the function is to insert data d into the nth position of the linked list,
You can call list_ The function of insert (head, N, d) is implemented;
(6) If the command is f, followed by an integer D, the function is to find data d in the linked list and return its bit order
Return - 1 not found. You can call list_ Find (head, d) function implementation;
(7) If the command is D, followed by an integer n, the function is to delete the data in the nth position of the linked list
Call list_ Delete (head, n) function.
```
###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
I C 5 100 200 300 400 500 P
F 500 N 3 23 N 5 31 P
D 4 P F 99
A 6 P
```
###Output example:
```out
100 200 300 400 500
index:5
100 200 23 300 31 400 500
100 200 23 31 400 500
Not Found!
100 200 23 31 400 500 6
```
###Input example:
```in
I A 100 A 200 A 300 C 4 400 500 600 700 P
F 800 F 500
N 4 4 N 5 5 P
D 2 D 2 D 2 P
D 2 D 2 D 2 P
D 1 D 1 P
D 1 D 1 P
```
###Output example:
```out
100 200 300 400 500 600 700
Not Found!
index:5
100 200 300 4 5 400 500 600 700
100 5 400 500 600 700
100 600 700
seven hundred
List is empty!
```







answer:If there is no answer, please comment