WAP To creat Single Linklist and enter Middle node.

#include<stdio.h>
#include<conio.h>

//Def:-WAP To creat Single Linklist and enter Middle node.
struct linklist
{
   int no;
   struct linklist *next;
};
typedef struct linklist node;
void main()
{
  void creat(node*);
  void display(node*);
  node *insfir(node*);
  void inslast(node*);
  void insmid(node*);
  node *head;
  clrscr();
  head=(node*)malloc(sizeof(node));
  creat(head);
  display(head);
  head=insfir(head);
  display(head);
  inslast(head);
  display(head);
  insmid(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("\nEnterred Node is=>%d",list->no);
    list=list->next;
 }
}

void insmid(node *list)
{
  node *new1;
  int n1;
  new1=(node*)malloc(sizeof(node));
  printf("\nWhich Number You enter node=>");
  scanf("%d",&n1);
  while(list->next!=NULL)
  {
    if(list->no==n1)
    {
      new1->next=list->next;
      list->next=new1;
      printf("\nEnter The Middle node=>");
      scanf("%d",&new1->no);
    }
    list=list->next;
}
}

void inslast(node *list)
{
  node *new1;
  new1=(node*)malloc(sizeof(node));
 // printf("\nEnter The last node=");
 // scanf("%d",&new1->no);
  while(list->next!=NULL)
  {
    list=list->next;
  }
  list->next=new1;
  new1->next=NULL;
  printf("\nEnter The last node=");
  scanf("%d",&list->no);
  }


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;
}
WAP To creat Single Linklist and enter Middle node. WAP To creat Single Linklist and enter Middle node. Reviewed by Unknown on 5:37:00 PM Rating: 5

No comments:

Powered by Blogger.