0% found this document useful (0 votes)
11 views6 pages

Pract 7

Hdjjdhj

Uploaded by

Shubham Rajbhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Pract 7

Hdjjdhj

Uploaded by

Shubham Rajbhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <stdio.

h>

#include <stdlib.h>

typedef struct Node {

int data;

struct Node *next;

struct Node *prev;

} Node;

Node* createNode(int data) {

Node* newNode = (Node*) malloc(sizeof(Node));

newNode->data = data;

newNode->next = NULL;

newNode->prev = NULL;

return newNode;

void insertNode(Node** head, int data) {

Node* newNode = createNode(data);

if (*head == NULL) {

*head = newNode;

} else {

Node* temp = *head;

while (temp->next != NULL) {

temp = temp->next;

temp->next = newNode;

newNode->prev = temp;

void deleteNode(Node** head, int data)

Node* temp = *head;

while (temp != NULL) {


if (temp->data == data) {

if (temp->prev != NULL) {

temp->prev->next = temp->next;

} else {

*head = temp->next;

if (temp->next != NULL) {

temp->next->prev = temp->prev;

free(temp);

return;

temp = temp->next;

printf("");

void printList(Node* head) {

while (head != NULL) {

printf("%d ", head->data);

head = head->next;

printf("NULL\n");

int main() {

Node* head = NULL;

int choice, data;

while (1) {

printf("1. Insert a node\n");

printf("2. Delete a node\n");

printf("3. Print the list\n");

printf("4. Exit\n");
printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1:

printf("Enter the number to insert: ");

scanf("%d", &data);

insertNode(&head, data);

break;

case 2:

printf("Enter the number to delete: ");

scanf("%d", &data);

deleteNode(&head, data);

break;

case 3:

printList(head);

break;

case 4:

return 0;

default:

printf("Invalid choice. Please try again.\n");

return 0;
}

You might also like