Saturday, 27 August 2011


#include<iostream.h>
#include<conio.h>
int main()
{
const int N=10;
for(int i=0;i<N;i+)
{
for(int j=0;j<2*N;j++)
if(j<N-j||N+j)
{
cout<<" ";
}
else
{
cout<<"*";
}
cout<<"\n";
}

stackusing Arr


#include<iostream.h>
#include<conio.h>
class StackUsingArr
{private: int s[10];
 int top;
 public:
      StackUsingArr();
      void push(int item);
      int pop();
      int peak();
      void display();
}x;

StackUsingArr::StackUsingArr() { top=-1;}

void StackUsingArr::push(int item)
{ if (top==9) cout<<"\n Stack is Full\n"<<endl;
  else
    { top++;
      s[top]=item;
    }
}

int StackUsingArr::pop()
{int n=-9999;
 if (top == -1) cout<<"The Stack is Empty\n";
 else
 {n= s[top];
 top--;}
 return n;
}

int StackUsingArr::peak()
{ int n=-9999;
  if (top ==-1) cout<<"\n The stack is Empty\n";
  else n=s[top];
  return n;
}

void StackUsingArr::display()
{ for(int i=0;i<=top;i++)
  {cout.width(5);
   cout<<s[i];
  }
  cout<< " <-- top "<<endl;
}

void main()
{
 clrscr();
 x.push(8);
 x.push(7);
 x.push(5);
 x.push(2);
 cout<<"\nThe elements of the stack\n";
 x.display();
 int m=x.peak();
 cout<<"\nThe topmost element is"<<m<<endl;
 cout<<"\n After calling peak the stack is\n";
 x.display();
 m=x.pop();
 cout<<"\nAfter deleting a topmost element "<<m<<"  the stack is..\n";
 x.display();
 getch();
}

Thursday, 25 August 2011

Program: Infix to Postfix notatio...

B Bhaskara Rao: B.Tech DS Unit-2 Program: Infix to Postfix notatio...: Click here to open....

Data Structures : Unit-2 Material .....

B Bhaskara Rao: B.Tech Data Structures : Unit-2 Material .....: Click here to open....

Programs: Infix to Prefix notatio...

B Bhaskara Rao: B.Tech DS Unit-2 Programs: Infix to Prefix notatio...: Click here to open....

Programs: Towers of Hanoi

B Bhaskara Rao: B.Tech DS Unit-2 Programs: Towers of Hanoi: Click here to open....

Stack using Arrays

stackLin


#include<iostream.h>
#include<conio.h>
class StackUsingLink
{private: struct node
  { int data;
     node *link;
  } *top;
 public:
      StackUsingLink();
      void push(int item);
      int  pop();
      int  peak();
      void display();
}x;

StackUsingLink::StackUsingLink() { top=NULL;}

void StackUsingLink::push(int item)
{ node *temp;
  temp=new node;
  if (temp==NULL)
   cout<<"\n Stack is Full\n"<<endl;
  else
    { temp->data = item;
      temp->link = top;
      top=temp;
    }
}

int StackUsingLink::pop()
{int n=-9999;
 if (top == NULL) cout<<"The Stack is Empty\n";
 else
 {n=top->data;
 top=top->link;}
 return n;
}

int StackUsingLink::peak()
{ int n=-9999;
  if (top ==NULL) cout<<"\n The stack is Empty\n";
  else n=top->data;
  return n;
}

void StackUsingLink::display()
{ node *temp;temp=top;
  if (temp !=NULL)
  { cout<< "top ---> ";
    while(temp != NULL)
    {cout.width(5);
    cout<<temp->data;
    temp=temp->link;
    }
   cout<<endl;
  }
  else cout<<"\n The stack is empty...\n"<<endl;
}

void main()
{
 clrscr();
 x.push(8);
 x.push(7);
 x.push(5);
 x.push(2);
 cout<<"\nThe elements of the stack\n";
 x.display();
 int m=x.peak();
 cout<<"\nThe topmost element is"<<m<<endl;
 cout<<"\n After calling peak the stack is\n";
 x.display();
 m=x.pop();
 cout<<"\nAfter deleting a topmost element "<<m<<"  the stack

is..\n";
 x.display();
 getch();
}