Data Structure Term - Paper ON
Data Structure Term - Paper ON
Data Structure Term - Paper ON
Term - Paper
ON
STACKS & QUEUES IMPLEMENTATION_
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define NULL 0
main()
{
struct node
{
int data,n;
struct node *link;
};
int n,item;
typedef struct node node;
node *temp,*sp=NULL;
while(1)
{
//clrscr(); //This program is designed using VC++ Compiler if you are using the
Turbo C compiler then you may use clrscr() here
printf("Please select your choice\n1. PUSH\n2. POP\n3. Search\n4. Display\n5. Ex!
t\n");
scanf("%d",&n);
switch(n)
{
case 1:
printf("Enter the data to PUSH into Stack\n");
scanf("%d",&item);
temp=(node *) malloc(sizeof(node));
temp->data=item;
temp->link=sp;
sp=temp;
break;
case 2:
if(sp==NULL)
{
printf("\nSTACK underflow\n");
getch();
}
else
{
item=sp->data;
sp=sp->link;
printf("\nPOP Successful Removed Data Is %d",item);
getch();
}
break;
case 3:
if(sp==NULL)
{
printf("\nSTACK underflow\n");
}
else
{
temp=sp;
printf("\nEnter data to search from Stack");
scanf("%d",&item);
n=0;
while(temp->data!=item)
{
if(temp->link==NULL)
goto print;
temp=temp->link;
n++;
}
print:
if(temp->data==item)
{
printf("Data %d Found In Stack at position %d",item,n+1);
}
else
{
printf("Data not present in Stack");
}
getch();
break;
case 4:
if(sp==NULL)
{
printf("\nSTACK is empty\n");
}
else
{
temp=sp;
printf("\n%d",temp->data);
while(temp->link!=NULL)
{
temp=temp->link;
printf("\n%d",temp->data);
}
}
getch();
break;
case 5:
exit(0);
break;
}
}
}
}
#include<stdlib.h>
#include<conio.h>
#define SIZE 3
int top=-1;
//////////////////////////////////////////////////////////////
// //
// Implimentation Of QUEUE using LINKLIST //
// Created By //
// AnKuR sInGh //
// //
/////////////////////////////////////////////////////////////
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Queue{
return 0;
}
void print q()
{
struct Queue *qq;
int n,j,num;
n=0;
for (qq=q, num=0; qq; qq=qq->node, num++); /* enumerate items in queue */
if(num==NULL)
{
printf("No items currently in the Queue");
return;
}
printf("Here are the items in the Queue \n");
cycle:
for (j=0,qq=q; (j < n) && qq; qq=qq->node, j++); /* lets hop to the next node */
printf("%s \n",qq->item);
n++;
if(n<num)
goto cycle;
}
int main()
{
struct Queue *qq;
int i,num;
char in[100]; /* array of 100 bytes */
/* print to stdout */
printf("Welcome to the Queue!");
printf("\n Dequeue not implemented \n");
printf("Usage: \n");
input: /* input label */
printf("\n1. Add to the queue\n");
printf("2. Print number of items in Queue \n");
printf("3. Print the items in the Queue \n");
printf("4. Exit the program \n");
default:
printf("Tu esta estupido!");
goto input;
}
}
//******************************************************//
//*****IMPLIMENTATION OF QUEUE USING ARRAY*****//
//******************************************************//
#include<stdlib.h>
#include<conio.h>
#define SIZE 2
int rear=-1,front=-1;