{  int data;s struct Node *next; struct Node *prev; };   // Function to insert at the end void insertEnd(struct Node** start, int value) { // If the list is empty, create a single node // circular and doubly list   if (*start == NULL)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

#include <bits/stdc++.h>

using namespace std;

 // Structure of a Node

struct Node

int data;s

struct Node *next;

struct Node *prev;

};

 

// Function to insert at the end

void insertEnd(struct Node** start, int value)

{

// If the list is empty, create a single node

// circular and doubly list

  if (*start == NULL)

  {

struct Node* new_node = new Node;  new_node->data = value;

new_node->next = new_node->prev = new_node;

*start = new_node;

return;

  }

 // If list is not empty 

/* Find last node */

Node *last = (*start)->prev;

// Create Node dynamically

  struct Node* new_node = new Node;

new_node->data = value;

 // Start is going to be next of new_node

  new_node->next = *start;

 // Make new node previous of start

 (*start)->prev = new_node;

   // Make last preivous of new node

  new_node->prev = last;

   // Make new node next of old last

    last->next = new_node;

}

 // Function to insert Node at the beginning

// of the List,

void insertBegin(struct Node** start, int value)

{

  // Pointer points to last Node

   struct Node *last = (*start)->prev;

 struct Node* new_node = new Node;

new_node->data = value; // Inserting the data

  // setting up previous and next of new node

   new_node->next = *start;

 new_node->prev = last;

 // Update next and previous pointers of start

  // and last.

  last->next = (*start)->prev = new_node;

 // Update start pointer

   *start = new_node;

}

 // Function to insert node with value as value1.

// The new node is inserted after the node with

// with value2

void insertAfter(struct Node** start, int value1,int value2)

{

struct Node* new_node = new Node;

 new_node->data = value1; // Inserting the data

  // Find node having value2 and next node of it

  struct Node *temp = *start;

    while (temp->data != value2)

     temp = temp->next;

   struct Node *next = temp->next;

...

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY