Skip to content

Instantly share code, notes, and snippets.

@Nachiappan
Created June 13, 2010 18:36
Show Gist options
  • Save Nachiappan/436876 to your computer and use it in GitHub Desktop.
Save Nachiappan/436876 to your computer and use it in GitHub Desktop.
#include "stdio.h"
#include"conio.h"
#include"stdlib.h"
struct node
{
int value;
struct node *next;
}*last;
struct node *head;
struct node **Refptr=&head;
void push()
{
int value;
static int count=0;
printf("\n\n\tEnter the value : ");
scanf("%d",&value);
struct node *newnode= (struct node*)malloc(sizeof(struct node));
newnode->value=value;
newnode->next=NULL;
if(count==0)
{
head=newnode;
count++;
}
else
{
last->next=newnode;
}
last=newnode;
disp();
}
void disp()
{
printf("\n\n\tthe list is \t");
struct node *temp= (struct node*)malloc(sizeof(struct node));
temp=head;
while(temp!=NULL)
{
printf("%d ",temp->value);
temp=temp->next;
}
}
void Nthtime()
{
int count=0,cnt_value=0;
printf("\n\n\tEnter the value : ");
scanf("%d",&cnt_value);
if(head->next!=NULL)
{
struct node *temp= (struct node*)malloc(sizeof(struct node));
temp=head->next;
while(temp!=NULL)
{
if(temp->value==cnt_value)
{
count++;
}
temp=temp->next;
}
}
printf("\n\n\tNo. of times the %d value occured is %d",cnt_value,count);
}
int main()
{
int menu=0,ch=1;
clrscr();
printf("\n\n\tHello, world\n");
while(ch==1)
{
printf("\n\n\tWhat do u want to do?\n\n\t1.Push\n\t2.Calculate Repetitions\t:");
scanf("%d",&menu);
switch(menu)
{
case 1:
push();
break;
case 2:
Nthtime();
break;
}
printf("\n\n\tDo you want to continue? : (press 1 to continue) : ");
scanf("%d",&ch);
}
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment