I have written a very simple example for Linked list....
but i guess I am doing something wrong with function call to print it...
can someone help here!
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node {
int data;
struct node *next;
}
struct node* build(){
struct node* head = NULL;
struct node* third = NULL;
struct node* second = NULL;
head = (struct node *)malloc(sizeof(struct node));
second = (struct node *)malloc(sizeof(struct node));
third = (struct node *)malloc(sizeof(struct node));
head->data = 1;
head->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = NULL;
return head;
}
void printlist(head){
struct node *current;
struct node *lhead;
current = lhead;
if(current!= NULL)
{
do
{
printf("%d\t",current->data);
current = current->next;
} while (current!= lhead);
printf("\n");
}
else
printf("The list is empty\n");
}
int main(){
struct node *list = NULL;
build(list);
printlist(list);
}
thanks!