Question

Problem 3 will have the following class Node.

static class Node

{

public char data;

public Node next;

public Node previous;

};

3. Answer all the sub-questions but for the following circular doubly-linked list with the external reference P2 given in the below figure, write the statements of each following question.

2

You can only use pointer P2 to access the doubly-linked list, write program statements to do the following, each question is independent based on the original status.

1) Display the content of the nodes in alphabetical order from B to T.

2) Replace ‘E’ by ‘M’ and replace ‘S’ by ‘R’.

3) Delete the node containing ‘T’

4) Inserting ‘D’ after node ‘B’ and before node ‘E’.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

System.out.println(P2.previous.previous.data);

System.out.println(P2.previous.data);

System.out.println(P2.data);

System.out.println(P2.next.data);

2) P2.previous.data = 'M';

P2.data = 'R';

3)

Node curr = P2.next;

P2.next = curr.next;

curr.next.previous = P2;

curr.next = null;

curr.previous = null;

4) Node prev = P2.previous.previous;

Node curr = P2.previous;

Node new_node = new Node();

new_node.data = 'D';

prev.next = new_node;

new_node.previous = prev;

new_node.next = curr;

curr.previous = node_next;

Add a comment
Know the answer?
Add Answer to:
Problem 3 will have the following class Node. static class Node { public char data; public...
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
  • Create a cpp file that contains a constructor and destructor of a node in a circular...

    Create a cpp file that contains a constructor and destructor of a node in a circular doubly-linked list using the following header file: class CDLLNode { private: // these will contain the timestamp and content of the tweet as strings std::string time; std::string tweet; // these are pointers to the next and previous nodes in the CDLL CDLLNode *next; CDLLNode *prev; public: CDLLNode(const char *ti, const char *tw); ~CDLLNode(); friend class CDLL; };

  • A linked list is constructed of nodes described by the following structure: struct node{ char data;...

    A linked list is constructed of nodes described by the following structure: struct node{ char data; struct node *next; }; Assume a linked list containing a sentinel node is constructed from the above nodes. Write a function named "count"-prototyped as int count(struct node*sent)- that accepts a pointer to the sentinel node; counts the number of data (non-sentinel) nodes containing the character 'A'; and returns that count as the function value.

  • Exercise-2: 15 points Develop a node class and a doubly list class. The node class should have tw...

    Exercise-2: 15 points Develop a node class and a doubly list class. The node class should have two state variables namely data and nextNode. The doubly list class should contain the following methods: Middlelnsert- insert a node somewhere in the middle of the list Startinsert-insert a node at start of the Linked list Endinsert- insert a node at the end of the Linked list Delete-delete a node Traverse-prints all the node's data Reverse-reverses the linked list . . Note: Choose...

  • This is a c programming problem. Would you please help me to write this problem??? I...

    This is a c programming problem. Would you please help me to write this problem??? I really appreciate it if you add comments for explanation step by step. Thank you. Reverse a Doubly linked list using recursion: Given a doubly linked list. Reverse it using recursion. Original Doubly linked list: next pointer - DDHIHI Null prev painter Reversed Doubly linked list: next pointer Start Pointer Null prev pointer Include: a) A struct for a node of the doubly linked list....

  • could somone please help me to complete this ! public class MyLinkedList<AnyType> { private Node<AnyType> head,...

    could somone please help me to complete this ! public class MyLinkedList<AnyType> { private Node<AnyType> head, tail; private int size; public MyLinkedList() { this.head = null; this.tail = null; this.size = 0; } //1.Insert a node at the end of the list public void insert(AnyType data) { Node<AnyType> newNode = new Node(); newNode.data = data; if (head == null) { head = newNode; tail = newNode; head.next = null; tail.next = null; } else { tail.next = newNode; tail =...

  • Here is the IntegerLinkedList_incomplete class: public class IntegerLinkedList { static class Node { /** The element...

    Here is the IntegerLinkedList_incomplete class: public class IntegerLinkedList { static class Node { /** The element stored at this node */ private int element; // reference to the element stored at this node /** A reference to the subsequent node in the list */ private Node next; // reference to the subsequent node in the list /** * Creates a node with the given element and next node. * * @param e the element to be stored * @param n...

  • Using Java You are given a Node class and a List class: public class Node {...

    Using Java You are given a Node class and a List class: public class Node {    int   data;     Node next; } public class List {     Node first; } You are also given a Stack class. The following functions are available for use: public class Stack { public boolean isEmpty(){}; public void push(int n){}; public int pop(){};} Write a Java method snglyRevToStck that pushes the data found in a linked list t in reverse order into the stack...

  • 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...

  • 5. Given the following definition of class Node: class Node { public int item; public Node...

    5. Given the following definition of class Node: class Node { public int item; public Node next; public Node ( int i, Node n ) { item = i; next = n; }; } and the following declarations: Node list, p, q; Assume the structure starts as below. Draw the structure created by executing the following statements. Each part is independent. list 1 2 3 4 5   [2] a) p = list; q = null; while ( p != null...

  • Could someone please summarize the following for my programming class? They are study questions for java...

    Could someone please summarize the following for my programming class? They are study questions for java What an association list is. How to test if an association list is empty. How to find the value associated with a key in an association list. How to add a key-value pair to an association list. How to delete a key-value pair from an association list. How efficient an association list is (using O notation). What a circular list is. What a circular...

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