Question: In this problem, you will create a linked list, and then print out the linked list in normal and reverse order. You will create three
In this problem, you will create a linked list, and then print out the linked list in normal and reverse order. You will create three functions, create (void), output(node_t *outhead), and reverse(node_t *head) to complete this task. Main function and the node definition is provided.
The node_t *create (void) will return a node_t type pointer pointing to the first node of the linked list. When this function is called, you will input integer to construct each node. The function will keep on running until you give nonnumeric input. Hint: use scanf("%d", &m), this function will return false when the input is not a number. [20 pt]
The void output(node_t *head) doesnt return anything. It will accept a node_t type pointer as argument and then print out the data in each node in order [20 pt]
The node_t reverse(node_t *head) returns a node_t type pointer and accept a node_t type pointer as argument. It will reconstruct the linked list by reversing its order and return. Make sure you only reverse the order of the original linked list by reconstructing the pointer but not creating another copy of the linked list. [50 pt]
Example run:
Input number: 12
Input number: 34
Input number: 9
Input number: 0
Input number: 7
Input number: 6
Input number: 2
The original list:
12 34 9 0 7 6 2
The new list:
2 6 7 0 9 34 12
#define NULL 0
typedef struct Node{
int num;
struct Node *next;
}node_t;
node_t *creat(void){
/* write your code here*/
}
void output(node_t *head){
/* write your code here*/
}
node_t * reverse(node_t *head){
/* write your code here*/
}
main(){
node_t *head;
head = creat();
printf(" The original list:");
output(head);
head = reverse(head);
printf(" The new list:");
output(head);
printf(" ");
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
