Author: Gour Ch. Saha
Contact for any query:: gour_ch_saha@yahoo.co.in
#include<stdio.h>
#define FALSE 0
#define TRUE 1
typedef struct node_tag
{
int data;
struct node_tag *next;
}node_type;
void print_link_list(node_type *root);
node_type *create_link_list(int n);
void print_link_list_reversly(node_type *head);
main()
{
int ret_val;
int n;
node_type *head;
printf("Give the number of node\n");
scanf("%d",&n);
head=create_link_list(n);
print_link_list(head);
print_link_list_reversly(head);
printf("\n");
}
void print_link_list_reversly(node_type *head)
{
if(head)
{
print_link_list_reversly(head->next);
printf("%d->",head->data);
}
}
void print_link_list(node_type *root)
{
node_type *temp;
for(temp=root;temp->next;temp=temp->next)
{
printf("%d-->",temp->data);
}
if(temp)
{
printf("%d\n",temp->data);
}
}
node_type *create_link_list(int n)
{
int i,a[30];
node_type *head,*temp,*root;
node_type *loop;
head = NULL;
for(i=0;i<n;i++)
{
a[i]=i+1;
}
for(i=0;i<n;i++)
{
temp=(node_type *)malloc(sizeof(node_type));
temp->data=a[i];
temp->next=NULL;
if(i==0)
{
root=temp;
head=temp;
}
else
{
head->next=temp;
head=head->next;
}
}
return root;
}