linked.c
linked.c
h>
#include <stdlib.h>
// Node structure
struct Node {
int data;
struct Node* next;
};
// Function prototypes
struct Node* newNode(int data);
void Insertfront(struct Node** head, int data);
void insertrear(struct Node** head, int data);
void insertposition(struct Node** head, int data, int
position);
void deletefront(struct Node** head);
void deleterear(struct Node** head);
void deleteposition(struct Node **head, int position);
void display(struct Node* node);
int main() {
struct Node* head = NULL;
int choice, i, data, position;
printf("Program is excuted by Raghavendra S Patil
\n");
while (1) {
printf("\n1. Insert at front\t2. Insert at rear\n3. Insert
at position\t4. Delete at front \n5. Delete at rear\t6. Delete at
position\n7. Display\n8. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter data: ");
scanf("%d", &data);
Insertfront(&head, data);
break;
case 2:
printf("Enter data: ");
scanf("%d", &data);
insertrear(&head, data);
break;
case 3:
printf("Enter data and position: ");
scanf("%d %d", &data, &position);
insertposition(&head, data, position);
break;
case 4:
deletefront(&head);
break;
case 5:
deleterear(&head);
break;
case 6:
printf("Enter position: ");
scanf("%d", &position);
deleteposition(&head, position);
break;
case 7:
display(head);
break;
case 8:
exit(0);
default:
printf("Invalid choice\n");
}
}
return 0;
}
// Function definitions
struct Node* newNode(int data) {
struct Node* node = (struct
Node*)malloc(sizeof(struct Node));
node->data = data;
node->next = NULL;
return node;
}