├── CircluarSingly.c ├── CircularDoubly.c ├── DoublyLinkedList.c ├── README.md └── SinglyLinkedList.c /CircluarSingly.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node *next; 7 | }; 8 | struct node *head; 9 | 10 | void beginsert(); 11 | void lastinsert(); 12 | void randominsert(); 13 | void begin_delete(); 14 | void last_delete(); 15 | void random_delete(); 16 | void display(); 17 | void search(); 18 | 19 | int main() 20 | { 21 | int choice = 0; 22 | while (choice != 7) 23 | { 24 | printf("\n....Main Menu....\n"); 25 | 26 | printf("\nChoose one option from the following list...\n"); 27 | printf("\nl.Insert in begining\n2.Insert at last\n3.Delete from Beginning\n4.Delete from last\n5.Search for an element\n6.Show\n7.Exit\n"); 28 | 29 | printf("\nEnter your choice: "); 30 | scanf("%d", &choice); // choice=3 31 | switch (choice) 32 | { 33 | case 1: 34 | beginsert(); 35 | break; 36 | case 2: 37 | lastinsert(); 38 | break; 39 | case 3: 40 | begin_delete(); 41 | break; 42 | case 4: 43 | last_delete(); 44 | break; 45 | case 5: 46 | search(); 47 | break; 48 | case 6: 49 | display(); 50 | break; 51 | case 7: 52 | exit(0); 53 | break; 54 | default: 55 | printf("Please enter valid choice.."); 56 | } 57 | } 58 | } 59 | void beginsert() 60 | { 61 | struct node *ptr, *temp; 62 | int item; 63 | ptr = (struct node *)malloc(sizeof(struct node)); 64 | if (ptr == NULL) 65 | { 66 | printf("\nOVERFLOW"); 67 | } 68 | else 69 | { 70 | printf("\nEnter the node data?"); 71 | scanf("%d", &item); 72 | ptr->data = item; 73 | if (head == NULL) 74 | { 75 | head = ptr; 76 | ptr->next = head; 77 | } 78 | else 79 | { 80 | temp = head; 81 | while (temp->next != head) 82 | temp = temp->next; 83 | ptr->next = head; 84 | temp->next = ptr; 85 | head = ptr; 86 | } 87 | printf("\nnode inserted\n"); 88 | } 89 | } 90 | void lastinsert() 91 | { 92 | struct node *ptr, *temp; 93 | int item; 94 | ptr = (struct node *)malloc(sizeof(struct node)); 95 | if (ptr == NULL) 96 | { 97 | printf("\nOVERFLOW\n"); 98 | } 99 | else 100 | { 101 | printf("\nEnter Data: "); 102 | scanf("%d", &item); 103 | ptr->data = item; 104 | if (head == NULL) 105 | { 106 | head = ptr; 107 | ptr->next = head; 108 | } 109 | else 110 | { 111 | temp = head; 112 | while (temp->next != head) 113 | { 114 | temp = temp->next; 115 | } 116 | temp->next = ptr; 117 | ptr->next = head; 118 | } 119 | printf("\nnode inserted\n"); 120 | } 121 | } 122 | void begin_delete() 123 | { 124 | struct node *ptr; 125 | if (head == NULL) 126 | { 127 | printf("\nUNDERFLOW"); 128 | } 129 | else 130 | { 131 | ptr = head; 132 | while (ptr->next != head) 133 | ptr = ptr->next; 134 | ptr->next = head->next; 135 | free(head); 136 | head = ptr->next; 137 | printf("\nnode deleted\n"); 138 | } 139 | } 140 | void last_delete() 141 | { 142 | struct node *ptr, *preptr; 143 | if (head == NULL) 144 | { 145 | printf("\nUNDERFLOW"); 146 | } 147 | else 148 | { 149 | ptr = head; 150 | while (ptr->next != head) 151 | { 152 | preptr = ptr; 153 | 154 | ptr = ptr->next; 155 | } 156 | preptr->next = ptr->next; 157 | free(ptr); 158 | printf("\nnode deleted\n"); 159 | } 160 | } 161 | void search() 162 | { 163 | struct node *ptr; 164 | int item, i = 0, flag; 165 | ptr = head; 166 | if (ptr == NULL) 167 | { 168 | printf("\nEmpty List\n"); 169 | } 170 | else 171 | { 172 | printf("\nEnter searching item: "); 173 | scanf("%d", &item); 174 | while (ptr != NULL) 175 | { 176 | if (head->data == item) 177 | { 178 | printf("Item found at location %d ", i + 1); 179 | flag = 0; 180 | break; 181 | } 182 | else 183 | { 184 | flag = 1; 185 | } 186 | i++; 187 | ptr = ptr->next; 188 | } 189 | if (flag == 1) 190 | { 191 | printf("Item not found\n"); 192 | } 193 | } 194 | } 195 | void display() 196 | { 197 | struct node *ptr; 198 | ptr = head; 199 | 200 | if (head == NULL) 201 | { 202 | printf("\nNothing to print "); 203 | } 204 | else 205 | { 206 | printf("\nPrinting values: "); 207 | while (ptr->next != head) 208 | { 209 | printf("%d\n", ptr->data); 210 | ptr = ptr->next; 211 | } 212 | printf("%d\n", ptr->data); 213 | } 214 | } -------------------------------------------------------------------------------- /CircularDoubly.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node *prev; 7 | struct node *next; 8 | }; 9 | struct node *head; 10 | 11 | void insertion_beginning(); 12 | void insertion_last(); 13 | void deletion_beginning(); 14 | void deletion_last(); 15 | void display(); 16 | void search(); 17 | 18 | int main() 19 | { 20 | int choice = 0; 21 | while (choice != 7) 22 | { 23 | printf("\n*Main Menu*****\n"); 24 | 25 | printf("\nChoose one option from the following list...\n"); 26 | printf("\nl.Insert in Beginning\n2.Insert at last\n3.Delete from Beginning\n4. Delete from last\n5.Search\n6.Show\n7.Exit\n"); 27 | 28 | printf("\nEnter your choice: "); 29 | scanf("\n%d", &choice); 30 | 31 | switch (choice) 32 | { 33 | case 1: 34 | insertion_beginning(); 35 | break; 36 | case 2: 37 | insertion_last(); 38 | break; 39 | case 3: 40 | deletion_beginning(); 41 | break; 42 | case 4: 43 | deletion_last(); 44 | break; 45 | case 5: 46 | search(); 47 | break; 48 | case 6: 49 | display(); 50 | break; 51 | case 7: 52 | exit(0); 53 | break; 54 | default: 55 | printf("Please enter valid choice.."); 56 | } 57 | } 58 | } 59 | void insertion_beginning() 60 | { 61 | 62 | struct node *ptr, *temp; 63 | int item; 64 | ptr = (struct node *)malloc(sizeof(struct node)); 65 | 66 | if (ptr == NULL) 67 | { 68 | printf("\nOVERFLOW"); 69 | } 70 | else 71 | { 72 | printf("\nEnter Item value"); 73 | scanf("%d", &item); 74 | 75 | ptr->data = item; 76 | if (head == NULL) 77 | { 78 | head = ptr; 79 | ptr->next = head; 80 | ptr->prev = head; 81 | } 82 | else 83 | { 84 | temp = head; 85 | 86 | while (temp->next != head) 87 | { 88 | temp = temp->next; 89 | } 90 | temp->next = ptr; 91 | ptr->prev = temp; 92 | head->prev = ptr; 93 | ptr->next = head; 94 | head = ptr; 95 | } 96 | printf("\nNode inserted\n"); 97 | } 98 | } 99 | void insertion_last() 100 | { 101 | struct node *ptr, *temp; 102 | int item; 103 | 104 | ptr = (struct node *)malloc(sizeof(struct node)); 105 | if (ptr == NULL) 106 | { 107 | printf("\nOVERFLOW"); 108 | } 109 | else 110 | { 111 | printf("\nEnter value"); 112 | scanf("%d", &item); 113 | ptr->data = item; 114 | if (head == NULL) 115 | { 116 | head = ptr; 117 | ptr->next = head; 118 | ptr->prev = head; 119 | } 120 | else 121 | { 122 | temp = head; 123 | while (temp->next != head) 124 | { 125 | temp = temp->next; 126 | } 127 | temp->next = ptr; 128 | ptr->prev = temp; 129 | head->prev = ptr; 130 | ptr->next = head; 131 | } 132 | } 133 | printf("\nNode inserted\n"); 134 | } 135 | void deletion_beginning() 136 | { 137 | struct node *temp; 138 | 139 | if (head == NULL) 140 | { 141 | printf("\nUNDERFLOW"); 142 | } 143 | else if (head->next == head) 144 | { 145 | head = NULL; 146 | free(head); 147 | 148 | printf("\nNode deleted\n"); 149 | } 150 | else 151 | { 152 | temp = head; 153 | while (temp->next != head) 154 | { 155 | temp = temp->next; 156 | } 157 | temp->next = head->next; 158 | head->next->prev = temp; 159 | free(head); 160 | head = temp->next; 161 | } 162 | } 163 | void deletion_last() 164 | { 165 | struct node *ptr; 166 | 167 | if (head == NULL) 168 | { 169 | printf("\nUNDERFLOW"); 170 | } 171 | else if (head->next == head) 172 | { 173 | head = NULL; 174 | free(head); 175 | printf("Item Deleted\n "); 176 | } 177 | else 178 | { 179 | ptr = head; 180 | if (ptr->next != head) 181 | { 182 | ptr = ptr->next; 183 | } 184 | ptr->prev->next = head; 185 | head->prev = ptr->prev; 186 | free(ptr); 187 | printf("\nItem deleted\n"); 188 | } 189 | } 190 | void display() 191 | { 192 | struct node *ptr; 193 | 194 | ptr = head; 195 | 196 | if (head == NULL) 197 | { 198 | printf("\nNothing to print"); 199 | } 200 | else 201 | { 202 | printf("\nPrinting values \n"); 203 | while (ptr->next != head) 204 | { 205 | printf("%d\n", ptr->data); 206 | ptr = ptr->next; 207 | } 208 | printf("%d\n", ptr->data); 209 | } 210 | } 211 | void search() 212 | { 213 | struct node *ptr; 214 | int item, i = 0, flag = 1; 215 | ptr = head; 216 | if (ptr == NULL) 217 | { 218 | printf("\nEmpty List\n"); 219 | } 220 | else 221 | { 222 | printf("\nEnter item which you want to search: "); 223 | scanf("%d", &item); 224 | if (head->data == item) 225 | { 226 | printf("Item found at location %d", i + 1); 227 | flag = 0; 228 | } 229 | else 230 | { 231 | while (ptr->next != head) 232 | { 233 | 234 | if (ptr->data == item) 235 | { 236 | printf("Item found at location %d ", i + 1); 237 | flag = 0; 238 | break; 239 | } 240 | else 241 | { 242 | flag = 1; 243 | } 244 | i++; 245 | ptr = ptr->next; 246 | } 247 | } 248 | if (flag != 0) 249 | { 250 | printf("Item not found\n"); 251 | } 252 | } 253 | } -------------------------------------------------------------------------------- /DoublyLinkedList.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | struct node *prev; 6 | struct node *next; 7 | int data; 8 | }; 9 | struct node *head; 10 | 11 | void insertion_beginning(); 12 | void insertion_last(); 13 | void insertion_specified(); 14 | void deletion_beginning(); 15 | void deletion_last(); 16 | void deletion_specified(); 17 | void display(); 18 | void search(); 19 | int main() 20 | { 21 | int choice = 0; 22 | while (choice != 9) 23 | { 24 | printf("\n*....Main Menu*****\n"); 25 | printf("\nChoose one option from the following list...\n"); 26 | printf("\nl.Insert in begining\n2.Insert at last\n3.Insert at any random location\n4.Delete from Beginning\n 5. Delete from last\n6.Delete the node after the given data\n7.Search\n8.Show\n9.Exit\n "); 27 | printf("\nEnter your choice: "); 28 | scanf("\n%d", &choice); 29 | 30 | switch (choice) 31 | { 32 | case 1: 33 | insertion_beginning(); 34 | break; 35 | case 2: 36 | insertion_last(); 37 | break; 38 | case 3: 39 | insertion_specified(); 40 | break; 41 | case 4: 42 | deletion_beginning(); 43 | break; 44 | case 5: 45 | deletion_last(); 46 | break; 47 | case 6: 48 | deletion_specified(); 49 | break; 50 | case 7: 51 | search(); 52 | break; 53 | case 8: 54 | display(); 55 | break; 56 | case 9: 57 | exit(0); 58 | break; 59 | default: 60 | printf("Please enter valid choice.."); 61 | } 62 | } 63 | } 64 | void insertion_beginning() 65 | { 66 | struct node *ptr; 67 | int item; 68 | ptr = (struct node *)malloc(sizeof(struct node)); 69 | if (ptr == NULL) 70 | { 71 | printf("\nOVERFLOW"); 72 | } 73 | else 74 | { 75 | printf("\nEnter Item value"); 76 | scanf("%d", &item); 77 | if (head == NULL) 78 | { 79 | ptr->next = NULL; 80 | ptr->prev = NULL; 81 | ptr->data = item; 82 | head = ptr; 83 | } 84 | else 85 | { 86 | ptr->data = item; 87 | ptr->prev = NULL; 88 | ptr->next = head; 89 | head->prev = ptr; 90 | head = ptr; 91 | } 92 | printf("\nNode inserted\n"); 93 | } 94 | } 95 | void insertion_last() 96 | { 97 | struct node *ptr, *temp; 98 | int item; 99 | ptr = (struct node *)malloc(sizeof(struct node)); 100 | 101 | if (ptr == NULL) 102 | { 103 | 104 | printf("\nOVERFLOW"); 105 | } 106 | else 107 | { 108 | printf("\nEnter value"); 109 | scanf("%d", &item); 110 | ptr->data = item; 111 | if (head == NULL) 112 | { 113 | ptr->next = NULL; 114 | ptr->prev = NULL; 115 | head = ptr; 116 | } 117 | else 118 | { 119 | temp = head; 120 | while (temp->next != NULL) 121 | { 122 | temp = temp->next; 123 | } 124 | temp->next = ptr; 125 | ptr->prev = temp; 126 | ptr->next = NULL; 127 | } 128 | } 129 | printf("innode Inserted\n"); 130 | } 131 | void insertion_specified() 132 | { 133 | struct node *ptr, *temp; 134 | int item, loc, i; 135 | ptr = (struct node *)malloc(sizeof(struct node)); 136 | 137 | if (ptr == NULL) 138 | { 139 | printf("\nOVERFLOW"); 140 | } 141 | else 142 | { 143 | printf("Enter the value"); 144 | scanf("%d", &item); 145 | 146 | ptr->data = item; 147 | printf("Enter the location"); 148 | scanf("%d", &loc); 149 | temp = head; 150 | for (i = 1; i < loc; i++) 151 | { 152 | temp = temp->next; 153 | if (temp == NULL) 154 | { 155 | printf("\n There are less than %d elements", loc); 156 | return; 157 | } 158 | } 159 | ptr->next = temp->next; 160 | ptr->prev = temp; 161 | temp->next = ptr; 162 | temp->next->prev = ptr; 163 | printf("\nnode inserted\n"); 164 | } 165 | } 166 | void deletion_beginning() 167 | { 168 | struct node *ptr; 169 | if (head == NULL) 170 | { 171 | printf("\n UNDERFLOW"); 172 | } 173 | else if (head->next == NULL) 174 | { 175 | head = NULL; 176 | free(head); 177 | printf("\nnode deleted\n"); 178 | } 179 | else 180 | { 181 | ptr = head; 182 | 183 | head = head->next; 184 | head->prev = NULL; 185 | free(ptr); 186 | 187 | printf("\nnode deleted\n"); 188 | } 189 | } 190 | void deletion_last() 191 | { 192 | struct node *ptr; 193 | if (head == NULL) 194 | { 195 | printf("\nUNDERFLOW"); 196 | } 197 | else if (head->next == NULL) 198 | { 199 | head = NULL; 200 | free(head); 201 | printf("\nnode deleted\n"); 202 | } 203 | else 204 | { 205 | ptr = head; 206 | while (ptr->next != NULL) 207 | { 208 | ptr = ptr->next; 209 | } 210 | ptr->prev->next = NULL; 211 | free(ptr); 212 | printf("\nnode deleted\n"); 213 | } 214 | } 215 | void deletion_specified() 216 | { 217 | struct node *ptr, *temp; 218 | int loc; 219 | printf("\n Enter the location node is to be deleted: "); 220 | scanf("%d", &loc); 221 | ptr = head; 222 | while (ptr->data != loc) 223 | ptr = ptr->next; 224 | if (ptr->next == NULL) 225 | { 226 | printf("\nCan't delete\n"); 227 | } 228 | else if (ptr->next->next == NULL) 229 | { 230 | ptr->next = NULL; 231 | } 232 | 233 | else 234 | { 235 | temp = ptr->next; 236 | ptr->next = temp->next; 237 | temp->next->prev = ptr; 238 | free(temp); 239 | printf("\nnode deleted\n"); 240 | } 241 | } 242 | void display() 243 | { 244 | struct node *ptr; 245 | ptr = head; 246 | if (ptr == NULL) 247 | { 248 | printf("Nothing to print"); 249 | } 250 | else 251 | { 252 | printf("\nprinting values while (ptr!=NULL) .\n"); 253 | while (ptr != NULL) 254 | { 255 | printf("\n%d", ptr->data); 256 | ptr = ptr->next; 257 | } 258 | } 259 | } 260 | void search() 261 | { 262 | struct node *ptr; 263 | int item, i = 0, flag; 264 | ptr = head; 265 | if (ptr == NULL) 266 | { 267 | printf("\nEmpty List\n"); 268 | } 269 | else 270 | { 271 | printf("\nEnter item which you want to search?\n"); 272 | scanf("%d", &item); 273 | 274 | while (ptr != NULL) 275 | { 276 | if (ptr->data == item) 277 | { 278 | printf("\nitem found at location %d ", i + 1); 279 | flag = 0; 280 | break; 281 | } 282 | else 283 | { 284 | flag = 1; 285 | } 286 | i++; 287 | ptr = ptr->next; 288 | } 289 | if (flag == 1) 290 | { 291 | printf("\nItem not found\n"); 292 | } 293 | } 294 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DSA-Linked-List -------------------------------------------------------------------------------- /SinglyLinkedList.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node *next; 7 | }; 8 | struct node *head; 9 | 10 | void beginsert(); 11 | void lastinsert(); 12 | void random_insert(); 13 | void begin_delete(); 14 | void last_delete(); 15 | void random_delete(); 16 | void display(); 17 | void search(); 18 | 19 | int main() 20 | { 21 | int choice = 0; 22 | while (choice != 9) 23 | { 24 | printf("\n...Choose One Option from the following List...\n"); 25 | printf("\nl.Insert in begining\n2.Insert at last\n3.Insert item at any location\n4.Delete from Beginning\n5.Delete from last\n6.Delete item from any location\n7.Search\n8.Show\n9.Exit\n"); 26 | 27 | printf("\nEnter your choice: "); 28 | scanf("\n%d", &choice); // choice=1 29 | 30 | switch (choice) 31 | { 32 | case 1: 33 | beginsert(); 34 | break; 35 | case 2: 36 | lastinsert(); 37 | break; 38 | case 3: 39 | random_insert(); 40 | break; 41 | case 4: 42 | begin_delete(); 43 | break; 44 | case 5: 45 | last_delete(); 46 | break; 47 | case 6: 48 | random_delete(); 49 | break; 50 | case 7: 51 | search(); 52 | break; 53 | case 8: 54 | display(); 55 | break; 56 | case 9: 57 | exit(0); 58 | break; 59 | default: 60 | printf("Invalid Choice.."); 61 | } 62 | } 63 | return 0; 64 | } 65 | void beginsert() 66 | { 67 | struct node *ptr; 68 | int item; 69 | ptr = (struct node *)malloc(sizeof(struct node *)); 70 | if (ptr == NULL) 71 | { 72 | printf("\nOVERFLOW"); 73 | } 74 | else 75 | { 76 | printf("\nEnter value: "); 77 | scanf("%d", &item); 78 | ptr->data = item; 79 | ptr->next = head; 80 | head = ptr; 81 | printf("Item inserted"); 82 | } 83 | } 84 | void lastinsert() 85 | { 86 | struct node *ptr, *temp; 87 | int item; 88 | ptr = (struct node *)malloc(sizeof(struct node)); 89 | if (ptr == NULL) 90 | { 91 | printf("\nOVERFLOW"); 92 | } 93 | else 94 | { 95 | printf("\nEnter value: "); 96 | scanf("%d", &item); 97 | ptr->data = item; 98 | if (head == NULL) 99 | { 100 | ptr->next = NULL; 101 | head = ptr; 102 | printf("Item inserted"); 103 | } 104 | else 105 | { 106 | temp = head; 107 | while (temp->next != NULL) 108 | { 109 | temp = temp->next; 110 | } 111 | temp->next = ptr; 112 | ptr->next = NULL; 113 | printf("Item inserted"); 114 | } 115 | } 116 | } 117 | void random_insert() 118 | { 119 | int i, loc, item; 120 | struct node *ptr, *temp; 121 | ptr = (struct node *)malloc(sizeof(struct node)); 122 | if (ptr == NULL) 123 | { 124 | printf("\nOVERFLOW"); 125 | } 126 | else 127 | { 128 | printf("Enter Value: "); 129 | scanf("%d", &item); 130 | ptr->data = item; 131 | printf("\nEnter the location: "); 132 | scanf("%d", &loc); 133 | temp = head; 134 | for (i = 1; i < loc; i++) 135 | { 136 | temp = temp->next; 137 | if (temp == NULL) 138 | { 139 | printf("\ncan't insert\n"); 140 | return; 141 | } 142 | } 143 | ptr->next = temp->next; 144 | temp->next = ptr; 145 | printf("Item inserted"); 146 | } 147 | } 148 | void begin_delete() 149 | { 150 | struct node *ptr; 151 | if (head == NULL) 152 | { 153 | printf("\nList is empty\n"); 154 | } 155 | else 156 | { 157 | ptr = head; 158 | head = ptr->next; 159 | free(ptr); 160 | printf("Item deleted from the begining ...\n"); 161 | } 162 | } 163 | void last_delete() 164 | { 165 | struct node *ptr, *ptrl; 166 | if (head == NULL) 167 | { 168 | printf("\nList is empty"); 169 | } 170 | else if (head->next == NULL) 171 | { 172 | head = NULL; 173 | free(head); 174 | printf("\nOnly node of the list deleted ..\n"); 175 | } 176 | else 177 | { 178 | ptr = head; 179 | while (ptr->next != NULL) 180 | { 181 | ptrl = ptr; 182 | ptr = ptr->next; 183 | } 184 | ptrl->next = NULL; 185 | free(ptr); 186 | printf("Item deleted\n"); 187 | } 188 | } 189 | void random_delete() 190 | { 191 | struct node *ptr, *ptrl; 192 | int loc, i; 193 | 194 | printf("\n Enter the location: "); 195 | scanf("%d", &loc); 196 | ptr = head; 197 | for (i = 0; i < loc; i++) 198 | { 199 | ptrl = ptr; 200 | ptr = ptr->next; 201 | if (ptr == NULL) 202 | { 203 | printf("\nCan't delete"); 204 | return; 205 | } 206 | } 207 | ptrl->next = ptr->next; 208 | free(ptr); 209 | printf("Item deleted at loc %d", loc); 210 | } 211 | void search() 212 | { 213 | struct node *ptr; 214 | int item, i = 0, flag; 215 | ptr = head; 216 | if (ptr == NULL) 217 | { 218 | printf("\nEmpty List\n"); 219 | } 220 | else 221 | { 222 | printf("\nEnter searching item: "); 223 | scanf("%d", &item); 224 | while (ptr != NULL) 225 | { 226 | if (ptr->data == item) 227 | { 228 | printf("Item found at location %d ", i + 1); 229 | flag = 0; 230 | } 231 | else 232 | { 233 | flag = 1; 234 | } 235 | i++; 236 | ptr = ptr->next; 237 | } 238 | if (flag == 1) 239 | { 240 | printf("Item not found\n"); 241 | } 242 | } 243 | } 244 | void display() 245 | { 246 | struct node *ptr; 247 | ptr = head; 248 | if (ptr == NULL) 249 | { 250 | printf("Nothing to print"); 251 | } 252 | else 253 | { 254 | printf("\nPrinting values while (ptr!=NULL).\n"); 255 | while (ptr != NULL) 256 | { 257 | printf("%d\n", ptr->data); 258 | ptr = ptr->next; 259 | } 260 | } 261 | } --------------------------------------------------------------------------------