0% found this document useful (0 votes)
5 views8 pages

Code 10

Uploaded by

Raj yadav
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)
5 views8 pages

Code 10

Uploaded by

Raj yadav
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/ 8

INPUT CODE :

#include <stdio.h>

#include <malloc.h>

#include <conio.h>

struct node {

struct node *prev;

int data;

struct node *next;

};

struct node *start = NULL, *last;

struct node *tn;

void creat_dll(int val) {

struct node *newnode, *tn;

newnode = (struct node*)malloc(sizeof(struct node));

newnode->data = val;

newnode->next = NULL;

if (start == NULL) {

start = newnode;

newnode->prev = NULL;

} else {

tn = start;

while (tn->next != NULL) {

tn = tn->next;

}
tn->next = newnode;

newnode->prev = tn;

last = newnode;

void insbeg(int val) {

struct node *newnode;

newnode = (struct node*)malloc(sizeof(struct node));

newnode->data = val;

newnode->next = start;

newnode->prev = NULL;

if (start != NULL) {

start->prev = newnode;

start = newnode;

void insmid(int val, int snv) {

struct node *newnode, *tn;

tn = start;

while (tn != NULL) {

if (tn->data == snv) {

newnode = (struct node*)malloc(sizeof(struct node));

newnode->data = val;

newnode->next = tn->next;
newnode->prev = tn;

if (tn->next != NULL) {

tn->next->prev = newnode;

tn->next = newnode;

return;

tn = tn->next;

printf("Node with value %d not found.\n", snv);

void insend(int val) {

struct node *newnode, *tn;

newnode = (struct node*)malloc(sizeof(struct node));

newnode->data = val;

newnode->next = NULL;

if (start == NULL) {

start = newnode;

newnode->prev = NULL;

} else {

tn = start;

while (tn->next != NULL) {

tn = tn->next;

tn->next = newnode;
newnode->prev = tn;

last = newnode;

void delbeg() {

if (start == NULL) {

printf("List is empty\n");

return;

start = start->next;

if (start != NULL) {

start->prev = NULL;

void delmid(int snv) {

struct node *tn = start;

while (tn != NULL) {

if (tn->next != NULL && tn->next->data == snv) {

tn->next = tn->next->next;

if (tn->next != NULL) {

tn->next->prev = tn;

return;

}
tn = tn->next;

printf("Node with value %d not found.\n", snv);

void delend() {

if (start == NULL) {

printf("List is empty\n");

return;

tn = start; // Declare the variable at the beginning

if (tn->next == NULL) {

start = NULL;

} else {

while (tn->next->next != NULL) {

tn = tn->next;

tn->next = NULL;

last = tn;

void displayforward() {

struct node *tn = start;


if (start == NULL) {

printf("List is empty\n");

return;

while (tn != NULL) {

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

tn = tn->next;

printf("\n");

void displayreverse() {

struct node *tn = last;

if (last == NULL) {

printf("List is empty\n");

return;

while (tn != NULL) {

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

tn = tn->prev;

printf("\n");

void search(int snv) {

struct node *tn = start;


int pos = 1;

while (tn != NULL) {

if (tn->data == snv) {

printf("%d found at position %d\n", snv, pos);

return;

tn = tn->next;

pos++;

printf("Node with value %d not found.\n", snv);

void countnode() {

struct node *tn = start;

int count = 0;

while (tn != NULL) {

count++;

tn = tn->next;

printf("Number of nodes: %d\n", count);

void main() {

clrscr();

creat_dll(13);
creat_dll(21);

creat_dll(35);

creat_dll(48);

insbeg(12);

insmid(52, 13);

insend(68);

delbeg();

delmid(21);

delend();

search(52);

displayforward();

displayreverse();

countnode();

printf("Operations completed.\n");

getch();

OUTPUT:

You might also like