Singly non circular linked list
As we learn the basic of linked list in a previous tutorial we got a basic idea of implementing linked list.
Singly non circular linked list is a one type of linked list where singly linked list means we are having a node with data and its next node address i.e.

And the name non-circular states that the last node of a linked list does not point to any node which contain it value null as shown below.

Last having null indicates it end (Non circular).
Program
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 | #include<stdio.h>#include<conio.h>struct node{ int data; struct node *next;}struct node *start;void insert_beg(void);void insert_end(void);void insert_before(void);void display(void);void deletion(void);void destroy(void);void main(void){int ch;start=NULL;do{printf(“\n 1. insert_beg\n 2. insert_end\n 3. insert_before\n 4. Display\n 5. Deletion\n 6.Destroy\n7.Exit”);scanf(“%d”,&ch);switch(ch){case 1: insert_beg(); break;case 2:insert_end();break;case 3:insert_before();break;case 4:display();break;case 5:deletion();break;case 6:destroy();break;case 7:exit(0);break;}}while(ch!=7);}void insert_beg(void){struct node *nn;nn=(strcut node *)malloc(sizeof(struct node));printf(“Enter data”);scanf(“%d”,&nn->data);if(start==NULL){nn->next=NULL;start=nn;}else{nn->next=start;start=nn;}}void insert_end(void){struct node *nn ,*temp;nn=(strcut node *)malloc(sizeof(struct node));printf(“Enter data”);scanf(“%d”,&nn->data);if(start==NULL){nn->next=NULL;start=nn;}else{temp=start;while(temp->next!=NULL){temp=temp->next;}temp->next=nn;nn->next=NULL;}}void insert_before(void){struct node *nn ,*temp,*ptemp;int x;if(start==NULL){printf(“SLL is empty”);return;}printf(“Enter data which you want to insert the node”);scanf(“%d”,&x);if(x==start->data){insert_beg(); return;}temp=start;while(temp!=NULL && temp->data!=x){ptemp=temp;temp=temp->next;}if(temp==NULL){printf(“%d does not exist:”,x);}else{nn=(strcut node *)malloc(sizeof(struct node));printf(“Enter data”);scanf(“%d”,&nn->data);ptemp->next=nn;nn->next=temp;}}void display(void){struct node *temp;if(start==NULL){printf(“\n SLL is empty”);return;}tempt=start;while(temp!=NULL){printf(“%d”,temp->data);temp=temp->next;}}void deletion(void) {struct node *ptemp,*temp;int x;if(start==NULL){printf(“\n SLL is empty”);return;}printf(“Enter data to delete”);sf(“%d”,&x);if(x==start->data){{temp=start;start=start->next;free(temp);return;}}void destroy(void) {struct node *temp,*dp;if(start==NULL){printf(“\n SLL is empty”);return;}temp=start;while(temp!=NULL){dp=temp;temp=temp->next;free(dp);}start=NULL;} |
Output
1.Insert_beg
2.Insert_end
3.Insert_before
4.Display
5.Deletion
6.Destroy
7.Exit
4
SLL is empty.
1.Insert_beg
2.Insert_end
3.Insert_before
4.Display
5.Deletion
6.Destroy
7.Exit
1
Enter data:
10
1.Insert_beg
2.Insert_end
3.Insert_before
4.Display
5.Deletion
6.Destroy
7.Exit
4
10
1.Insert_beg
2.Insert_end
3.Insert_before
4.Display
5.Deletion
6.Destroy
7.Exit
7