Q) A C program of simple Linked List without any user defined function.
SOl)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
struct node
{
int data;
struct node*next;
};
typedef struct node node ;
int d ;
node *start=NULL, temp, *save ;
int option ;
printf("Enter the data for the node\n ");
scanf("%d",&d) ;
start=(node*)malloc(sizeof (node)) ;
start->data ;
start->next= NULL ;
save = start ;
printf("Do you want to enter more data \n" ) ;
printf("Press 1 for yes otherwise 0 \n ");
scanf("%d",&option) ;
while(option==1)
{
printf("Enter the data for the node\n ") ;
scanf("%d", &d) ;
temp = (node*)malloc(sizeof (node)) ;
temp->data=d;
temp->next= NULL ;
save->next= temp ;
save=temp;
printf("Do you want to enter more data \n") ;
printf("Press 1 for yes otherwise 0 \n ");
scanf("%d", &option) ;
}
printf("The Linked List is \n") ;
while(start!= NULL)
{
printf("%d->", start->data);
start = start->next ;
}
getch();
}
No comments:
Post a Comment