Description

Please write a function 'void ReverseList(Node head)*' to print the sequence in reverse order.

請撰寫函式 void ReverseList(Node* head),反向印出數列。

Input

Input contains multiple numbers, ended with -1, representing the values in the linked list.

輸入包含多個數字,以-1作為結尾,代表 linked list 中的值。

Output

Print the sequence in reverse order with each number separated by a '->'.

請將數列反向印出,每個數字中間以->隔開。

Sample Input 1

1 3 9 5 7 -1

Sample Output 1

7->5->9->3->1

Given Code


#include <stdio.h>
#include <stdlib.h>

typedef struct node{
    int data;
    struct node* next;
}Node;

void ReverseList(Node* head){
    
}
/*
int main(){
    int num;
    int choice;
	Node *head = NULL, *cur;
	cur = head;
	while (scanf("%d", &num) != EOF){
        if(num == -1)
            break;
		Node* new = (Node*)malloc(sizeof(Node)); 
        new->data = num;
		new->next = NULL;
		if (head == NULL)
			head = new;
		else
			cur->next = new;
		cur = new;
    }
    ReverseList(head);
}
*/

answer sheet: https://www.geeksforgeeks.org/reverse-a-linked-list/