#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);
}
Monday, July 11, 2011
Program to print content of linked list reversely.
Bimalpreet Singh
About The Author
He has interest in programming in C, C++ and Java. He has been programming since 2007. He is the Founder of "Era of Skills".
You can follow him on Facebook
0 Comments