EXP2
EXP2
operations:
Insert Display, Delete, Search,
Count,
EXPERIMENT NO-2
Search, Count
SOURCE CODE:
#include <stdio.h>
#include <stdlib.h>
int data;
} Node;
int main() {
while (1) {
printf("1. Insert\n");
printf("2. Display\n");
printf("3. Delete\n");
printf("4. Search\n");
printf("5. Count\n");
EXPERIMENT NO-02 Implementing of Doubly Linked List with their
operations:
Insert Display, Delete, Search,
Count,
printf("6. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
insert(&head, value);
break;
case 2:
display(head);
break;
case 3:
scanf("%d", &value);
delete(&head, value);
break;
case 4:
scanf("%d", &value);
if (result != NULL)
else
break;
case 5:
EXPERIMENT NO-02 Implementing of Doubly Linked List with their
operations:
Insert Display, Delete, Search,
Count,
break;
case 6:
exit(0);
default:
return 0;
new_node->data = data;
new_node->prev = NULL;
new_node->next = NULL;
if (*head == NULL) {
*head = new_node;
} else {
temp = temp->next;
temp->next = new_node;
new_node->prev = temp;
}
EXPERIMENT NO-02 Implementing of Doubly Linked List with their
operations:
Insert Display, Delete, Search,
Count,
if (head == NULL) {
printf("List is empty.\n");
return; }
head = head->next; }
printf("NULL\n");
if (*head == NULL) {
return;
temp = temp->next;
if (temp == NULL) {
return;
if (temp == *head) {
*head = temp->next;
if (*head != NULL)
(*head)->prev = NULL;
EXPERIMENT NO-02 Implementing of Doubly Linked List with their
operations:
Insert Display, Delete, Search,
Count,
} else {
if (temp->next != NULL)
temp->next->prev = temp->prev;
if (temp->prev != NULL)
temp->prev->next = temp->next; }
free(temp);
if (head->data == data)
return head;
head = head->next;}
return NULL;}
int count = 0;
count++;
head = head->next; }
return count;}
OUTPUT:
EXPERIMENT NO-02 Implementing of Doubly Linked List with their
operations:
Insert Display, Delete, Search,
Count,