Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct c{
- int d;
- struct c *p;
- };
- struct c *top = NULL;
- void push(int a)
- {
- struct c *n;
- n=(c*) malloc (sizeof(c));
- n->d=a;
- n->p =top;
- top=n;
- //printf("%d\n",n->d);
- }
- void display () {
- struct c *temp;
- temp=top;
- if(top==0){
- printf("Stack is full\n");
- }
- else {
- while(temp!=0){
- printf("%d\n",temp->d);
- temp=temp->p;
- }
- }
- }
- void peek()
- {
- if(top==0)
- {
- printf("Stack is full\n");
- }
- else{
- printf("\nfirst data is %d\n",top->d);
- }
- }
- void pop(){
- struct c *t;
- t=top;
- if(top==0)
- {
- printf("Stack is FUll\n");
- }
- else{
- //printf("deleted number %d\n",top->d);
- top=top->p;
- free(t);
- }
- }
- int main()
- {
- //push(3);
- //push(5);
- // push(10);
- printf("How Many number you want: ");
- int n,i;
- scanf("%d",&n);
- for(i=1;i<=n;i++)
- {
- push(i);
- }
- display();
- peek();
- int k;
- printf("Enter how many number you want to delete : ");
- scanf("%d",&k);
- for(i=1;i<=k;i++)
- {
- pop();
- }
- peek();
- display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement