Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- struct node
- {
- int data;
- struct node *next;
- }rear=NULL;
- void insert_behind(int x)
- {
- struct node *p=(struct node *)malloc(sizeof(struct node));
- p->data=x;
- p->next=NULL;
- if(rear==NULL)
- {
- rear=p;
- p->next=p;
- return;
- }
- p->next=rear->next;
- rear->next=p;
- rear=p;
- }
- void insert_front(int x)
- {
- struct node *p=(struct node *)malloc(sizeof(struct node));
- p->data=x;
- p->next=NULL;
- if(rear==NULL)
- {
- rear=p;
- p->next=p;
- return;
- }
- p->next=rear->next;
- rear->next=p; //rear is not moved
- }
- void traverse_print()
- {
- struct node *temp;
- if(rear!=NULL)
- {
- temp=temp->next; //traverse from front node
- while(temp!=rear->next)
- {
- printf("%d\t"p->data);
- p=p->next;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement