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

PROGRAMMING:Bidirectional circular linked list operation of leading node

Luz5年前 (2021-05-10)题库592
This topic requires reading in a series of integers, which are inserted into the head and tail of the bidirectional circular linked list in turn, and then output the linked list in order and reverse order.
Linked list node type can be defined as
```
typedef int DataType;
typedef struct LinkedNode{
DataType data;
struct LinkedNode *prev;
struct LinkedNode *next;
}LinkedNode;
```
Linked list types can be defined as
```
typedef struct LinkedList{
int length; /* Length of linked list*/
LinkedNode head; /* The head node of bidirectional circular list*/
}LinkedList;
```
The function initializing the linked list can be declared as
```
void init_ list(LinkedList *list);
```
Functions that assign nodes can be declared as
```
LinkedNode *alloc_ node(DataType data);
```
The function inserted in the header can be declared as
```
void push_ front(LinkedList *list, DataType data);
```
Tail inserted functions can be declared as
```
void push_ back(LinkedList *list, DataType data);
```
Functions traversed sequentially can be declared as
```
void traverse(LinkedList *list);
```
Functions traversed in reverse order can be declared as
```
void traverse_ back(LinkedList *list);
```
###Input format:
Enter a line of integers (space separated) ending with - 1.
###Output format:
The first line outputs the result of sequential traversal of the linked list, and the second line outputs the result of reverse traversal.
###Input example:
Here is a set of inputs. For example:
```in
1 2 3 4 5 6 -1
```
###Output example:
```out
5 3 1 2 4 6
6 4 2 1 3 5
```







answer:If there is no answer, please comment