We can display the data of the circular singly linklist in two process
We can easily program it using recursive function
#include<stdio.h> #include<conio.h> struct linklist { int i; struct linklist *next; }; typedef struct linklist node; //prototype declaration void ftol(node *,node *); void ltof(node *,node *); node *head; int main() { int c,i,pos; while(1) { printf("2. First to last display\n"); printf("3. last to First display\n"); printf("15. Exit\n"); printf("Enter Your choice : "); scanf("%d",&c); switch(c) { case 2: ftol(head,head); // First to last display break; case 3: ltof(head,head); // last to First display break; case 15: exit(0); } } return 0; }
void ftol(node *l,node *h) { if(l->next!=h) { printf("%d\n",l->i); ftol(l->next,h); } else { printf("%d\n",l->i); } } void ltof(node *l,node *h) { if(l->next!=h) { ltof(l->next,h); printf("%d\n",l->i); } else { printf("%d\n",l->i); } }