Data-structure Mini-project using Stack, Queue and Tree

Data-structure Mini-project using Stack, Queue and Tree


Screenshots

1. Home 

Home page of Data-structure Microproject

2. Stack Operations

Stack operation in Data-structure project

3. Queue Operation 

Queue operation in Data-structure project

4. Tree Operation

Tree operation in data-structure

Description : 

In this project we have 3 main data-structures 
1. Stack 
2. Queue
3. Tree

In stack we have three operations 
 1. Push (Inserting new element or number in the stack.)
 2. Pop  (Deleting the element which at the TOP position in the stack. )
 3. Display ( Displaying all the elements in the stack..)

In Queue 
1. Insert ( Inserting new element in the Queue.)
2. Delete (Deleting the firstly entered number in the queue.)
3. Display (To show all the elements in the Queue.)

In Tree
1. Insert (Inserting new element in the Tree.)
2. Search (Searching elements in the Tree.)
3. Display (To show all nodes in the Tree.)



Source code:

#include<stdio.h>
#include<conio.h>
#define max 500
#define max1 500
int top=-1,stack[max];
void push();
void pop();
void display();
int front=-1,rear=-1,queue[max1];
void insert();
void del();
void disp();
struct node *start=NULL,*temp,*temp1;
void insert_tree();
void traverse();
void search();
struct node
{
 int info;
 struct node *left,*right;

};
int main()
{ int ch,ch1,ch2,ch3;
 a:
  clrscr();
  printf("\t\t................MICRO-PROJECT..................\n");
  printf("1. STACK OPERATION\n");
  printf("2. QUEUE OPERATION\n");
  printf("3. TREE OPERATION\n");
  printf("4. EXIT\n");
  printf("Enter Your Choice");
  scanf("%d",&ch);
  switch(ch)
  {

   case 1:  while(1)
                  {
                   clrscr();
                   printf("\t\t............Stack Operations............\n");
                   printf("1.  PUSH\n");
                   printf("2.  POP\n");
                   printf("3.  DISPLAY\n");
                   printf("4.  EXIT\n");
                   printf("Enter your choice");
                   scanf("%d",&ch1);

                   switch(ch1)
                   {
                    case 1:
                                  push();
                                   break;
                    case 2:
                                   pop();
                                   break;
                    case 3:
                                   display();
                                   break;
                    case 4: goto a;
                    default:printf("Invalid Choice");

                   }
                   }
                   break;
   case 2:
                   while(1)
                  {
                   clrscr();
                   printf("\t\t............Queue Operations............\n");
                   printf("1.  INSERT\n");
                   printf("2.  DELETE\n");
                   printf("3.  DISPLAY\n");
                   printf("4.  EXIT\n");
                   printf("Enter your choice");
                   scanf("%d",&ch2);

                   switch(ch2)
                   {
                    case 1:
                                   insert();
                                   break;
                    case 2:
                                   del();
                                   break;
                    case 3:
                                   disp();
                                   break;
                    case 4: goto a;
                    default:printf("Invalid Choice");

                   }
                   }

                              break;
   case 3:
                    while(1)
  {
   clrscr();

   printf("1.Insert\n2.Search\n3.Display\n4.Exit");
   printf("\n Enter choice");
   scanf("%d",&ch3);
   switch(ch3)
   {
   case 1:insert_tree();
                  break;
   case 2: search();
                  break;
   case 3:traverse();
                 break;
   case 4: return 0;
   default:printf("Invalid choice");

   }


  }
                              break;

   case 4: return 0;

   default:printf("Invalid Choice");




  }



 getch();
}

void push()
{ int ele;
 clrscr();
  if(top==max-1)
  printf("Stack overflowed");
  else
  {
   printf("Enter element");
   scanf("%d",&ele);
   top=top+1;
   stack[top]=ele;
   }
}
void pop()
{
 int ele;
 clrscr();
  if(top==-1)
   printf("Stack underflowed");
   else
   {
    ele=stack[top];
    top=top-1;
    printf("Element poped:%d",ele);
     getch();
   }
}
void display()
{
  int i;
  clrscr();
  printf("Stack Elements:");
  for(i=top;i>-1;i--)

  printf("\n%d",stack[i]);
  getch();


}
void insert()
{
 int ele;
  clrscr();
 if(rear==max1-1)
  printf("Queue overflowed");
  else
  {
   if(front==0||front==-1)
   {
     front=0;
     printf("Enter element");
     scanf("%d",&ele);
     rear=rear+1;
     queue[rear]=ele;
   }
 }
}
void disp()
{
 int i;
 clrscr();
 printf("Queue Elements:");
 for(i=front;i<=rear;i++)
 printf("\t%d",queue[i]);

 getch();
}
void del()
{    int ele;
 clrscr();
 if(front==rear||front>rear)
  printf("Queue underflowed");
  else
  {
    ele=queue[front];
    front=front+1;
    printf("\nDeleted element:%d",ele);
  }

 getch();
}
void insert_tree()
{
 int ele;

 printf("Enter element");
 scanf("%d",&ele);
 if(start==NULL)
 {
 temp=(struct node*)malloc(sizeof(struct node));
 temp->info=ele;
 temp->left=NULL;
 temp->right=NULL;
 start=temp;
 }
 else
 {
  temp1=(struct node*)malloc(sizeof(struct node));
  temp1->info=ele;
  temp1->left=NULL;
  temp1->right=NULL;
  temp=start;
  while(1)
  { if(ele<temp->info)
   {
    if(temp->left==NULL)
    {
     temp->left=temp1;
     break;
    }
    temp=temp->left;
    }
    else
    {
      if(ele>temp->info)
      {
       if(temp->right==NULL)
       {
               temp->right=temp1;
               break;
       }
       temp=temp->right;
      }

    }
    }
    }
    }
void traverse()
{
 printf("\n%d",start->info);
 temp=start->left;
 while(temp!=NULL)
 {
   printf("\n%d",temp->info);
   temp=temp->left;
 }
  temp=start->right;
 while(temp!=NULL)
 {
   printf("\n%d",temp->info);
   temp=temp->right;
 }
 getch();
}
void search()
{ int f=0,s;
  temp=start;
  printf("Which element you want to search");
  scanf("%d",&s);
  while(temp!=NULL)
  {
    if(s==temp->info)
    {
     f=1;
     break;
    }
    if(s>temp->info)
    {
     temp=temp->right;
    }
    if(s<temp->info)
    {
     temp=temp->left;
    }

  }

  if(f==1)
   printf("Element found");
   else
   printf("Element not found");

   getch();
}


                        Click to download source code 

Post a Comment

0 Comments