Insertion at Beginning Edited
Insertion at Beginning Edited
#include <stdio.h>
#include <stdlib.h>
int main() {
int isExit = 0;
while (!isExit) {
char *choices[] = {"Insertion at beginning", "Display", "Exit"};
int choice = getChoice(choices, 3);
switch (choice) {
case 1:
insertion();
break;
case 2:
display();
break;
case 3:
isExit = 1;
break;
default:
printf("Invalid option.\n");
}
}
return 0;
}
void insertion() {
Node *newnode = (Node *) malloc(sizeof(Node)); // Use pointer
if (newnode == NULL) {
printf("Memory allocation failed.\n");
return;
}
void display() {
Node *temp = head;
if (temp == NULL) {
printf("Linked List is empty\n");
} else {
printf("Linked List elements: ");
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
}