Monday, April 6, 2015

No. of times Nodes repeated

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
   int data;
  struct node * next;
};

void append(struct node **q)
{
 struct node *temp;
    temp=*q;
   if(temp==NULL)
  {
   *q=(struct node *)malloc(sizeof(struct node));
    printf("\nenter the data");
   scanf("%d",&(*q)->data);
   (*q)->next=NULL;
}
else
{
  while(temp->next!=NULL)
   temp=temp->next;

   temp->next=(struct node *)malloc(sizeof(struct node));
    temp=temp->next;

  printf("\nenter the data");
    scanf("%d",&temp->data);
  temp->next=NULL'
  }
}

void count(struct node **q)
{
    struct node *temp,*n;
    int count=1;
       temp=*q;
       n=NULL;
printf("\nenter the no. to search");
  n=(struct node *)malloc(sizeof(struct node));  //new node to store the enter data uses for comparison
    scanf("%d",&n->data);
   n->next=NULL;  //node created
   while(temp->next!=NULL)
  {
    if(temp->data==n->data)  //camparing the input value to the node value
      count++;
    temp=temp->next;
  }
printf(\n %d repeated %d times");
   temp->data;
getch();
}

}
void display(struct node *q)
{
  struct node *temp;
  temp=q;
    while(temp!=NULL)
    {
      printf(" %d",temp->data);
      temp=temp->next;
     }
}

void display(struct node *q)
{
  struct node *temp;
  temp=q;
    while(temp!=NULL)
    {
      printf(" %d",temp->data);
      temp=temp->next;
     }
}

void main()
{
 struct node *start,*start2;
 start=NULL; //empty list1
  printf("\nenter the nodes in link list : ")  append(&start);
 append(&start);
 append(&start);
 append(&start);
  display(start) ;
 count(&start);
getch();
}
 The Output Will Be :

No comments:

Post a Comment