Professional Documents
Culture Documents
#include<stdio.h> #include<conio.h> #include<iostream.h> class intstack { private: int *Arr; int size; int top; public: intstack(int n) { size=n; top=0; Arr= new int(size); } void push(int obj) { if(top==size)
cout<<"\nstack is full\n"; else Arr[top++]=obj; } int pop() { if(top==0) cout<<"\nstack is empty"; else return Arr[--top]; return -1; } }; void main() { intstack stack(10); clrscr(); stack.push(5); stack.push(7); cout<<stack.pop()<<endl; cout<<stack.pop()<<endl; getch();
void enqueue(int x) { if (f+1==t) cout<<"queue is Full"; else { arr[f]=x; f=(f+1)%size; } } int dequeue() { if (f==t) { cout<<"queue is Empty"; return-1; } else { t=(t+1) % size;
return arr[t-1];
} return -1; }
getch(); }
class intstack { private: int *Arr; int Size; int Top; public: intstack (int n) //constructor { Size=n; Top=0; Arr = new int(Size); } //end of intstack
void push (int x) { if (Top==Size) cout<<"\nThe stack is full"; else Arr[Top++] = x; } //end of push
int pop() { if (Top==0) cout<<"\n The stack is empty"; else return Arr[--Top] ; return -1; } //end of pop
}; // end of class
void main() { clrscr(); long long int n; int m,r; cout<<"Enter an Decimal Number: "; cin>>n; m=ceil(log10(n)/log10(2)); intstack stack(m+1); while (n>1) { r=n%2; n=n/2; stack.push(r); } stack.push(n); while (stack.isempty() == 0)
cout<<stack.pop(); getch();
} //end of main