XII-COMPUTER SCIENCE--DATA STRUCTURE POGRAMS-2013-14 (STACK,QUEUE-- DYNAMIC LINKED LIST and ARRAY IMPLEMENTATION)

// PROG-5  Array (static) implementation of STACK
#include <iostream.h>
#include<ctype.h>
#include<conio.h>
#define MAXSIZE 10
int stack[MAXSIZE];
int top=-1;  //index pointing to the top of stack
int main()
{
void push(int);
int pop();
char ch='y';int d;
while(ch=='y')
{
   cout<<"\n  Enter a data to be entered/pushed in stack  :  ";
   cin>>d;
  push(d);
cout<<"\n press y to continue   PUSH  ";
cin>>ch;
}
ch='y';
while(ch=='y')
{
   cout<<"\n  NOW- CURRENT data present at top of   stack  IS:  ";
  cout<<pop();
cout<<"\n press y to continue POP     ";
cin>>ch;
}
getch();
return 0;
}
void push(int y)
{
   if(top==MAXSIZE-1)
   {
   cout<<endl<<"STACK FULL--STACK OVERFLOW OCCURED";
   return;
   }
   else
   {
   top++;
   stack[top]=y;
   }
}
int pop()
{
int a;
   if(top==-1)
   {
   cout<<endl<<"STACK EMPTY--STACK UNDERFLOW OCCURED";
   return 0;
   }
   else
   {
   a=stack[top];top--;
   }
return a;
}

------------------------------------------------
// PROG -- 6  Linked List (pointer/dynamic)implementation of STACK

#include<conio.h>
#include<iostream.h>
struct node {
  int data;
  node * next;
  }* start=NULL,* end,* p,*newptr,*tmp;
  node * create(int d)
  {    p=new node;
       p->data=d;
       p->next=NULL;
       return p;
   }
   void insert_at_begining(node * p)
   {
   if(start==NULL)
   start=p;
   else
   p->next=start;
   start=p;
   }
   void display(node * p)
   {
      while(p)
        { cout<<p->data<<"  ----- "; p=p->next;
        }
    }

void main()
{
char ch='y';int d;
while(ch=='y')
{
   cout<<"\n  Enter a data  :  ";
   cin>>d;
  newptr= create(d);
  insert_at_begining(newptr);
   display(start);
cout<<"\n press y to continue  .....";
cin>>ch;
}
getch();
}
------------------------------------------------
// PROG -- 7  Linked List (pointer/dynamic)implementation of QUEUE

#include<conio.h>
#include<iostream.h>
struct node {
  int data;
  node * next;
  }* start=NULL,* end,* p,*newptr;
  node * create(int d)
  {    p=new node;
       p->data=d;
       p->next=NULL;
       return p;
   }
   void insert_at_end(node * p)
   {      if( start== NULL)
             {
             end=start=p;
             }
             else
             {
      end->next=p;
      end=p;
      }
   }
  
   void display(node * p)
   {
      while(p)
        { cout<<p->data<<" ......  "; p=p->next;
                }
    }
void main()
{
char ch='y';int d;
while(ch=='y')
{
   cout<<"\n  Enter a data  :  ";
   cin>>d;
  newptr= create(d);
  insert_at_end(newptr);
  cout<<"\n CURRENT CONTENT OF QUEUE IS :\n";
   display(start);
cout<<"\n press y to continue     ";
cin>>ch;
}
getch();
}

 

Popular posts from this blog

XII- CS-- SOLVED SQL queries (SQL PRACTICAL ASSIGNMENS)

SQL--HOME ASSIGNMENTS(XII Class)

Python-MySQL Connectivity