fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node{int data;struct node* ptr;};
  4. struct node *front=NULL;
  5. struct node *rear=NULL;
  6.  
  7. void insert(int ele){struct node* new = (struct node*)malloc(sizeof(struct node));
  8. new->data=ele;new->ptr=NULL;
  9. if(rear==NULL && front==NULL)
  10. {rear=new;front=new;return;}
  11. rear->ptr=new;rear=new;}
  12.  
  13. int del(){struct Node* new = front;
  14. if(front==NULL) {printf("empty");return;}
  15. if(front == rear) {front = rear = NULL;}
  16. else{front = front->ptr;free(new);}
  17. }
  18. void disp(){struct node* new = front;
  19. while(new != NULL) {
  20. printf("%d",new->data);
  21. new = new->ptr;}
  22. printf("\n");
  23. }
  24. int main(){insert(1);insert(2);insert(3);disp();del();disp();return 0;}
  25.  
  26.  
Success #stdin #stdout 0s 4392KB
stdin
Standard input is empty
stdout
123
23