We can read or display the link list element in two way.
Here we use two recursive function for it. Now we create the basic environment of the link list.
#include<stdio.h> #include<conio.h> struct slinearlinklist { int i; struct slinearlinklist *next; }; typedef struct slinearlinklist node; //prototype declaration void ftol(node *); void ltof(node *); node *head=NULL; int main() { int c,i,pos; while(1) { printf("\n1. Display From First to Last\n"); printf("2. Display From Last to First\n"); printf("3. Exit\n"); printf("Enter Your choice : "); scanf("%d",&c); switch(c) { case 1: fotl(head);// First To Last break; case 2: ltof(head); // Last To First break; case 3: exit(0); } } }
void ftol(node *l) { if(l!=NULL) { printf("%d\n",l->i); ftol(l->next); } }
void ltof(node *l) { if(l!=NULL) { ltof(l->next); printf("%d\n",l->i); } }