Monday, July 11, 2011

Program to print content of linked list reversely.


#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
main()
{
struct node *start;
int n;
void create(struct node **, int);
extern void show(struct node *);
start=NULL;
printf("\nEnter number of elements you want in your array: ");
scanf("%d",&n);
create(&start,n);
printf("\nthe program printing  linked list reversely: ");
show(start);
getch();
}

void create(struct node **q,int n)
{
int i;
struct node *lst;
struct node *p;
lst=NULL;
for(i=1;i<=n;i++)
{
 p=(struct node *)malloc(sizeof(struct node));
 printf("Enter the %d element :",i);
 scanf("%d",&(p->data));
 p->next=NULL;
 if(*q==NULL)
    *q=p;
 else
   lst->next=p;
  lst=p;
}
}

void show(struct node *ptr)
{
if(ptr==NULL)
{
  return;
}
show(ptr->next);
printf(" %d",ptr->data);

}


Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More