├── LICENSE ├── README.md ├── append in singly linked list in c.c ├── creating song playlist using doubly linked list.c ├── creating two singly linked list.c ├── doubly linked list operation insertion.c └── singly linked list insert function.c /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Supreeth2319 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # linked-list -------------------------------------------------------------------------------- /append in singly linked list in c.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node*link; 7 | }; 8 | struct node*head=NULL; 9 | int len; 10 | void append(void); 11 | int length(void); 12 | void display(void); 13 | void main() 14 | { 15 | int ch; 16 | while(1) 17 | { 18 | printf("linked list operations\n"); 19 | printf("1.append\n"); 20 | printf("2.length of the linked list"); 21 | Printf("3.display the linked list"); 22 | printf("enter your choice"); 23 | scanf("%d",&ch); 24 | switch(ch) 25 | { 26 | case 1:append(); 27 | break; 28 | case 2:len=length(); 29 | printf("length of the list is %d",len); 30 | break; 31 | case 3:display(); 32 | break; 33 | case 4:exit(0); 34 | default : printf("invlid choice"); 35 | 36 | } 37 | } 38 | 39 | } 40 | void append() 41 | { 42 | struct node*temp; 43 | temp=(struct node*)malloc(sizeof(struct node)); 44 | printf("enter the data to be appended"); 45 | scanf("%d",&temp->data); 46 | temp->link=NULL; 47 | if(head==NULL) 48 | { 49 | head=temp;; 50 | } 51 | else 52 | { 53 | struct node*p; 54 | p=head; 55 | while(p->link!=NULL) 56 | { 57 | p=p->link; 58 | } 59 | p->link=temp; 60 | 61 | } 62 | } 63 | int length() 64 | { 65 | int count=0; 66 | struct node*temp; 67 | temp=head; 68 | while(temp!=NULL) 69 | { 70 | count=count+1; 71 | temp=temp->link; 72 | } 73 | return count; 74 | } 75 | void display() 76 | { 77 | struct node*temp; 78 | temp=head; 79 | if(temp==NULL) 80 | { 81 | printf("linked list id empty "); 82 | } 83 | else 84 | { 85 | while(temp!=NULL) 86 | { 87 | printf("%d->",temp->data); 88 | temp=temp->link; 89 | 90 | } 91 | printf("\n\n"); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /creating song playlist using doubly linked list.c: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /creating two singly linked list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node*link; 7 | }; 8 | struct node*head=NULL; 9 | struct node*head2=NULL; 10 | void insert_at_end(void); 11 | void display(void); 12 | void concatinate(void); 13 | void main() 14 | { 15 | int ch; 16 | while(1) 17 | { 18 | printf("-------------------------"); 19 | printf("linked list operations\n"); 20 | printf("1.append\n"); 21 | printf("2.display\n"); 22 | printf("3.exit\n"); 23 | Printf("----‐--------------------"); 24 | printf("enter your choice"); 25 | scanf("%d",&ch); 26 | switch(ch) 27 | { 28 | case 1:insert_at_end(); 29 | break; 30 | case 2:display(); 31 | break; 32 | case 3:exit(0); 33 | break; 34 | default : printf("invlid choice"); 35 | } 36 | } 37 | } 38 | void insert_at_end() 39 | { 40 | struct node*temp1,*temp2; 41 | temp1=(struct node*)malloc(sizeof(struct node)); 42 | temp2=(struct node*)malloc(sizeof(struct node)); 43 | printf("enter the data to be appended to link list 1"); 44 | scanf("%d",&temp1->data); 45 | temp1->link=NULL; 46 | printf("enter the data to be appended to link list 2"); 47 | scanf("%d",&temp2->data); 48 | temp2->link=NULL; 49 | if(head==NULL&&head2==NULL) 50 | { 51 | head=temp1; 52 | head2=temp2; 53 | } 54 | else 55 | { 56 | struct node*p; 57 | p=head; 58 | while(p->link!=NULL) 59 | { 60 | p=p->link; 61 | } 62 | p->link=temp1; 63 | struct node*q; 64 | q=head2; 65 | while(q->link!=NULL) 66 | { 67 | q=q->link; 68 | } 69 | q->link=temp2; 70 | 71 | } 72 | } 73 | void display() 74 | { 75 | struct node*temp1,*p; 76 | temp1=head; 77 | p=head2; 78 | if(temp1==NULL && p==NULL) 79 | { 80 | printf(" linked list id empty "); 81 | } 82 | else 83 | { 84 | while(temp1!=NULL) 85 | { 86 | printf("%d->",temp1->data); 87 | temp1=temp1->link; 88 | 89 | } 90 | printf("\n\n"); 91 | while(p!=NULL) 92 | { 93 | printf("%d->",p->data); 94 | p=p->link; 95 | 96 | } 97 | printf("\n\n"); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /doubly linked list operation insertion.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node*llink; 7 | struct node*rlink; 8 | }; 9 | struct node*head=NULL; 10 | int len; 11 | void insert_at_specific_position(void); 12 | int length(void); 13 | void display(void); 14 | void insert_at_beggining(void); 15 | int main() 16 | { 17 | int ch; 18 | while(1) 19 | { 20 | printf("-----------------------------"); 21 | printf("linked list operations\n"); 22 | printf("1 insert_at_beggining\n"); 23 | printf("2.insert at specific point\n"); 24 | printf("3.length of the doubly link list\n"); 25 | printf("4.display doubly linked list\n"); 26 | Printf("---‐----------------------------"); 27 | printf("enter your choice"); 28 | scanf("%d",&ch); 29 | switch(ch) 30 | { 31 | case 1:insert_at_beggining(); 32 | break; 33 | case 2:insert_at_specific_position(); 34 | break; 35 | case 3:len=length(); 36 | printf("length of the list is %d",len); 37 | break; 38 | case 4:display(); 39 | break; 40 | case 5:exit(0); 41 | default : printf("invlid choice"); 42 | 43 | } 44 | } 45 | return 0; 46 | } 47 | int length() 48 | { 49 | int count=0; 50 | struct node*temp; 51 | temp=head; 52 | while(temp!=NULL) 53 | { 54 | count=count+1; 55 | temp=temp->rlink; 56 | } 57 | return count; 58 | } 59 | void insert_at_beggining() 60 | { 61 | struct node*temp; 62 | temp=(struct node*)malloc(sizeof(struct node)); 63 | printf("enter the node"); 64 | scanf("%d",&temp->data); 65 | temp->rlink=NULL; 66 | temp->llink=NULL; 67 | if(head==NULL) 68 | { 69 | head=temp; 70 | } 71 | else 72 | { 73 | temp->rlink=head; 74 | head->llink=temp; 75 | head=temp; 76 | } 77 | } 78 | void insert_at_specific_position() 79 | { 80 | int i=1,loc; 81 | struct node*temp,*p; 82 | temp=(struct node*)malloc(sizeof(struct node)); 83 | printf("enter the location where you want to insert"); 84 | scanf("%d",&loc); 85 | len=length(); 86 | if(loc>len) 87 | { 88 | printf("invalid location"); 89 | printf("list has only %d elements",len); 90 | } 91 | else 92 | { 93 | temp=(struct node*)malloc(sizeof(struct node)); 94 | printf("enter the node data"); 95 | scanf("%d",&temp->data); 96 | temp->llink=NULL; 97 | temp->rlink=NULL; 98 | p=head; 99 | while(irlink; 102 | i++; 103 | } 104 | temp->rlink=p->rlink; 105 | p->rlink->llink=temp; 106 | temp->llink=p; 107 | p->rlink=temp; 108 | } 109 | } 110 | void display() 111 | { 112 | struct node*temp; 113 | temp=head; 114 | while(temp!=NULL) 115 | { 116 | printf("%d->",temp->data); 117 | temp=temp->rlink; 118 | } 119 | printf("\n\n"); 120 | } 121 | -------------------------------------------------------------------------------- /singly linked list insert function.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node*link; 7 | }; 8 | struct node*head=NULL; 9 | int len; 10 | void insert_at_end(void); 11 | int length(void); 12 | void display(void); 13 | void insatbeg(void); 14 | void main() 15 | { 16 | int ch; 17 | while(1) 18 | { 19 | printf("\nlinked list operations\n"); 20 | printf("1.insert at end\n"); 21 | printf("2.length\n"); 22 | printf("3.display\n"); 23 | printf("\n5.add at beginning\n"); 24 | printf("4.add at specific position\n"); 25 | printf("enter your choice"); 26 | scanf("%d",&ch); 27 | switch(ch) 28 | { 29 | case 1:insert_at_end(); 30 | break; 31 | case 2:len=length(); 32 | printf("length of the list is %d",len); 33 | break; 34 | case 3:display(); 35 | break; 36 | case 5:insatbeg(); 37 | break; 38 | case 6:exit(0); 39 | default : printf("invlid choice"); 40 | 41 | } 42 | } 43 | 44 | } 45 | void insert_at_end() 46 | { 47 | struct node*temp; 48 | temp=(struct node*)malloc(sizeof(struct node)); 49 | printf("enter the data to be appended"); 50 | scanf("%d",&temp->data); 51 | temp->link=NULL; 52 | if(head==NULL) 53 | { 54 | head=temp; 55 | } 56 | else 57 | { 58 | struct node*p; 59 | p=head; 60 | while(p->link!=NULL) 61 | { 62 | p=p->link; 63 | } 64 | p->link=temp; 65 | 66 | } 67 | } 68 | int length() 69 | { 70 | int count=0; 71 | struct node*temp; 72 | temp=head; 73 | while(temp!=NULL) 74 | { 75 | count=count+1; 76 | temp=temp->link; 77 | } 78 | return count; 79 | } 80 | void display() 81 | { 82 | struct node*temp; 83 | temp=head; 84 | if(temp==NULL) 85 | { 86 | printf("linked list is empty there are no elements to display "); 87 | } 88 | else 89 | { 90 | while(temp!=NULL) 91 | { 92 | printf("%d->",temp->data); 93 | temp=temp->link; 94 | 95 | } 96 | printf("\n\n"); 97 | } 98 | } 99 | void insatbeg() 100 | { 101 | struct node*temp; 102 | temp=(struct node*)malloc(sizeof(struct node)); 103 | printf("enter the data to be appended"); 104 | scanf("%d",&temp->data); 105 | temp->link=NULL; 106 | if(head==NULL) 107 | { 108 | head=temp; 109 | } 110 | else 111 | { 112 | temp->link=head; 113 | head=temp; 114 | } 115 | 116 | } 117 | --------------------------------------------------------------------------------