Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct std
- {
- int id;
- struct std *next;
- struct std *prev;
- }*start=NULL,*end=NULL,*top=NULL;
- void f_insert()
- {
- struct std *newnode,*current;
- newnode=(struct std*)malloc(sizeof(struct std));
- printf("Enter the ID: ");
- scanf("%d",&newnode->id);
- newnode->next=NULL;
- newnode->prev=NULL;
- current=start;
- if(start==NULL){
- start=newnode;
- end=newnode;
- }
- else{
- newnode->next=current;
- current->prev=newnode;
- current=current->prev;
- start=current;
- }
- top=start;
- printf("POP successful\n");
- }
- void count()
- {
- struct std *current;
- int count=0;
- current=start;
- if(start==NULL)
- printf("stack is empty\n");
- else{
- while(current!=NULL)
- {
- count++;
- current=current->next;
- }
- printf("\nThere are %d number of nodes.\n\n",count);
- }
- }
- void l_delete()
- {
- struct std *current,*temp,*temp1,*temp2;
- current=start;
- if(start==NULL)
- printf("stack is empty\n");
- else if(start->next==NULL){
- start=NULL;
- end=NULL;
- top=start;
- }
- else{
- start=current->next;
- (current->next)->prev=NULL;
- top=start;
- }
- printf("\ndeleted successfully\nThe element is %d\n",current->id);
- }
- void display()
- {
- struct std *current;
- current=start;
- if(start==NULL)
- printf("stack is empty\n");
- else{
- count();
- printf("\nThe Top value is : %d\n",top->id);
- printf("\nThe link list by forward display:\n");
- while(current!=NULL)
- {
- printf("%d",current->id);
- if(current->next!=NULL)
- printf("-->");
- current=current->next;
- }
- printf("\n");
- }
- }
- int main()
- {
- while(1){
- int n;
- printf("\n1. push\n2. Pop\n3. display\nchose: ");
- scanf("%d",&n);
- if(n==1)
- f_insert();
- else if(n==2)
- l_delete();
- else if(n==3)
- display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement