/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int data;
struct node* next;
}node_t;
int node_insert(struct node *node_head, struct node *node) {
struct node *node_tmp;
node_tmp = node_head;
while(node_tmp->next != NULL) {
node_tmp = node_tmp->next;
}
node_tmp->next = node;
}
void print_node (struct node* node_head) {
struct node* node_tmp;
node_tmp = node_head;
while(node_tmp!= NULL) {
printf("data is %d\n", node_tmp->data);
node_tmp = node_tmp->next;
}
}
node_t *list_reverse (node_t *node_head) {
node_t * PREV;
node_t * CURR;
node_t * NEXT;
PREV = node_head;
CURR = node_head;
NEXT = node_head->next;
node_head->next = NULL;
// printf("%p\n", NEXT);
// printf("%p\n", node_head->next);
while(NEXT != NULL) {
CURR = NEXT;
NEXT = CURR->next;
CURR->next = PREV;
PREV = CURR;
}
//node_head = CURR;
return CURR;
}
int main()
{
node_t* HEAD = malloc(sizeof(node_t));
HEAD->data = 50;
HEAD->next = NULL;
node_t* node_2 = malloc(sizeof(node_t));
node_2->data = 70;
node_2->next = NULL;
node_t* node_3 = malloc(sizeof(node_t));
node_3->data = 90;
node_3->next = NULL;
node_insert(HEAD, node_2);
node_insert(HEAD, node_3);
print_node (HEAD);
HEAD = list_reverse(HEAD);
printf("\n");
print_node(HEAD);
return 0;
}