pointer of current node should be point to first node
I am trying to make circuler linkel list. I have created single linked list. In a code, pointer of current node point to previous node. I want to change pointer so that pointer of current node will point to first node in the list.
Code:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node * next;
};
struct node * ADD ( struct node *Head, int value)
{
struct node * new = malloc( sizeof(*new));
if( new != NULL )
{
new -> data = value;
new -> next = Head;
}
return new;
}
void show ( struct node* head)
{
struct node* current;
for ( current = head; current != NULL; current = current -> next )
{
printf("%d ", current -> data);
}
}
int main()
{
struct node *head = NULL;
head = ADD( head, 1);
head = ADD( head, 2);
head = ADD( head, 3);
show(head);
return 0;
}
3 2 1