Pages

Write a program to create single link list.

Wednesday, 29 May 2013

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
struct node
{
       int data;
       struct node *link;
};
struct node *n, *first, *this1;
int main()
{
    char ch;
    first=NULL;
    printf("Enter q to quit: ");
    ch=getche();
    while(ch!='q')
    {
           n=(struct node *)malloc(sizeof(struct node));
           printf("\nEnter data to store in node: ");
           scanf("%d", &n->data);
           n->link=NULL;
           if(first==NULL)
           {
                  first=n;
           }
           else
           {
                  this1=first;
                  while(this1->link!=NULL)
                  {
                          this1=this1->link;
                  }
                  this1->link=n;
           }
           printf("Press q to quit: ");
           ch=getche();
    }
    printf("\n");
    this1=first;
           while(this1!=NULL)
           {
                   printf("%d\n", this1->data);
                   this1=this1->link;
           }
    getch();
   
}
 

Search Box

Most Reading

Contact Form

Name

Email *

Message *