WAP To creat The single linklist and insert last node.

#include<stdio.h>
#include<conio.h>
//Def:->WAP To creat The single linklist and insert last node.
struct linklist
{
    int no;
    struct linklist *next;
};
typedef struct linklist node;
void main()
{
   void creat(node*);
   void display(node*);
   void inslast(node*);
   node *insfir(node*);
   node *head;
   clrscr();

   head=(node*)malloc(sizeof(node));
   creat(head);
   display(head);
  head= insfir(head);
   display(head);
   inslast(head);
   display(head);
   getch();
}

void creat(node *list)
{
  printf("\nEnter number -1 for end=>");
  scanf("%d",&list->no);
  if(list->no==-1)
  list->next=NULL;
  else
  {
    list->next=(node*)malloc(sizeof(node));
    creat(list->next);
  }
}

void display(node *list)
{
  while(list->next!=NULL)
  {
    printf("\nEnter Node is=>%d",list->no);
    list=list->next;
  }
}

node *insfir(node *list)
{
   node *new1;
   new1=(node*)malloc(sizeof(node));
   printf("\nEnter The first node=>");
   scanf("%d",&new1->no);
   new1->next=list;
   list=new1;
   return list;
}

void inslast (node *list)
{
  node *new1;
  new1=(node*)malloc(sizeof(node));
  while(list->next!=NULL)
  {
     list=list->next;
  }
   // printf("\nEnter The last node=>");
  //scanf("%d",&new1->no);
  list->next=new1;
  new1->next=NULL;
  printf("\nEnter The last node=>");
  scanf("%d",&list->no);
}
WAP To creat The single linklist and insert last node. WAP To creat The single linklist and insert last node. Reviewed by Unknown on 5:36:00 PM Rating: 5

No comments:

Powered by Blogger.