Skip to main content
Write a program to create and display singly link list using pointers.
CODING:
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
 int no;
 struct node *next;
};
struct node *first;
void creatlist()
{
 char ch='y';
 struct node *ptr,*nw;
 while(ch !='n')
 {
 printf("\nEnter item in list");
 nw=(struct node*)malloc(sizeof(struct node));
 scanf("%d",&nw->no);
 nw->next=0;
 if(first==0)
 {
  first=nw;
 }
 else
 {
  for(ptr=first ;ptr->next!=0; ptr=ptr->next);
 {
  ptr->next=nw;
 }
}
printf("\n Do you want to continue Y\n");
ch=getch();
}
}
void display()
{
 struct node *ptr;
 printf("item int list are");
 for(ptr=first;ptr!=0;ptr=ptr->next)
 {
  printf("\n %d",ptr->no);
 }
}
void main()
{
 clrscr();
 first=0;
 creatlist();
 display();
 getch();
}

Comments