Question

Write a C++ code to display the data member of the nodes started from the node pointed to by p and ending at the node pointed
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/* C++ code to Display data inclusive p to q

while(p != q->right){ // it runs from p to q (inclusive )

cout<<p->data<<" "; // prints data

p = p->right;

}

// Note if you have asked to write function below is function code

// function to display data between nodes p to q in c++

void display(node *p, node *q){

while(p != q->right){ // it runs from p to q (inclusive )

cout<<p->data<<" "; // prints data

p = p->right;

}

}

/* PLEASE UPVOTE */

Add a comment
Know the answer?
Add Answer to:
Write a C++ code to display the data member of the nodes started from the node...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • data structure using c++ CSC 220 Assignment 4 Total Points-15 Name: Give the diagram of the...

    data structure using c++ CSC 220 Assignment 4 Total Points-15 Name: Give the diagram of the doubly linked list implementation of the polynomials in two variables. Use the nodes with the members tag, coef, expo, next. 1. Write a C++ code to insert a node to the left of the node p in the double linked list shown below. (Each node has three fields: an data field that contains the information, and next and prev fields that contains pointers to...

  • v. 15 points) implementing data structure operations C++ code for a new public member function to...

    v. 15 points) implementing data structure operations C++ code for a new public member function to be added to the doubly linked list data structure used in class. Return the average value of all elements in the list ple a list of integers) Throws a length error exception if the list is empty. template «typename E> E& 0; average You may use loops or recursion as needed. If necessary, you may add private helper function0s) The definition of the DLinkedList...

  • C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and In...

    C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done...

  • C++ 1. Please use attached script for your reference to create the node structure and a...

    C++ 1. Please use attached script for your reference to create the node structure and a linked list class, say LinkedList, that has the following basic member methods:     constructor, destructor//IMPORTANT, display(), add_node(). 2. Please implement the following additional member methods:     Please feel free to change T with any data type you'd like to use for your node stricture's data type. -- addFirst(T data) // Adds an node with data at the beginning of the list -- pop() //...

  • (C++)Create a class node with private member data of int id (0 to 10) and char ctype (A to Z), generate random nodes and place them into a list. Sort the list according to id and display them, then mo...

    (C++)Create a class node with private member data of int id (0 to 10) and char ctype (A to Z), generate random nodes and place them into a list. Sort the list according to id and display them, then move them from the list to a priority queue (basing on the ctype) and then display the contents of the queue.

  • C++ You're given the pointer to the head nodes of two linked lists. Compare the data...

    C++ You're given the pointer to the head nodes of two linked lists. Compare the data in the nodes of the linked lists to check if they are equal. The lists are equal only if they have the same number of nodes and corresponding nodes contain the same data. Either head pointer given may be null meaning that the corresponding list is empty. Input Format You have to complete the int CompareLists (Node headA, Node* head B) method which takes...

  • Write a MIPS assembly language program that uses dynamic memory allocation to create and manage a...

    Write a MIPS assembly language program that uses dynamic memory allocation to create and manage a linked list data structure. Gives the user the following options:                         1. To create and add the first node to a linked list.          2. To add a single node to the pre-existing linked list.             The list must already exist before a new node can be added.            The nodes should be maintained in ascending order based on the data value within the nodes...

  • I need this in C++. This is all one question Program 2: Linked List Class For...

    I need this in C++. This is all one question Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...

  • Use MAT:AB to code 650:231 M.E. Computational Analysis and Design Finally, give the member force by...

    Use MAT:AB to code 650:231 M.E. Computational Analysis and Design Finally, give the member force by (see (8) in Project_2_Suppliment) PART A 15 Pts.] Consider the truss given by Fig. 2. The height of the truss is 3 ft. The cross sectional area and Young's modulus of each bar is a-I in, and E-30 Mpsi (106 lb/in2), respectively. The symbol # for the applied load indicates the unit of lb. The truss is supported by a pin at node 6...

  • Please write a c++ header file, class implementation file and main file that does all of...

    Please write a c++ header file, class implementation file and main file that does all of the following and meets the requirements listed below. Also include a Output of your code as to show that your program works and functions properly. EXERCISING A DOUBLY-LINKED LIST CLASS This project consists of two parts, the second of which appears below. For the first part, write a class that implements an unordered list abstract data type using a doubly-linked list with pointers to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT