Question

Please answer the following Questions with A,B,C... and I will give a thumbs up If you...

Please answer the following Questions with A,B,C... and I will give a thumbs up

If you can give a little context to why you chose that answer that'd be great too.

Which of the following are the right steps to remove and return the linear node pointed to by current if it is not the first node in the list and previous points to the node before current.

Question 1

previous.setNext(current.getNext());

return current;

current.setNext(previous.getNext());

return previous;

current.setPrevious(current.getNext());

return previous;

previous.setNext(current.getPrevious());

return previous;

Which of the following are the right step(s) to remove the first node of a linked list?

Question 2

front = front.getNext();

if (front == rear)

rear = front.getNext();

front = front.getNext();

front.setNext(rear);

none of the above

Which of the following are the right step(s) to remove the last node of a linked list assuming that current points to that node and that previous points to the node before current?

Question 3

previous.setNext(current);

rear = current;

rear.setPrevious(previous);

previous.setNext(null)

rear = previous;

none of the above

Which of the following are the right steps to advance the pointers in a loop that must keep track of current and previous while traversing a linked list?

Question 4

previous = current;

current = current.getNext();

current = current.getNext()

previous = current;

previous = current;

current = current.next;

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

Q1.

When removing current node, we need to set next node of previous node to current's next node.

previous.setNext(current.getNext());

(a)

Q2.

To remove first node of a linked list, we just need to move the front node to one node next

front = front.getNext();

(a)

Q3.

To remove last node, we need to set the previous node's next pointer to null
and make it as the rear

previous.setNext(null)
rear = previous

(c)

Q4.

To advance to the next element in loop, we need to make current node as previous and next node as current node
previous = current
current = current.getNext()

(a)

Add a comment
Know the answer?
Add Answer to:
Please answer the following Questions with A,B,C... and I will give a thumbs up If you...
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
  • Hi! Can someone can convert this java code to c++. ASAP thanks I will thumbs up Here's the code: ...

    Hi! Can someone can convert this java code to c++. ASAP thanks I will thumbs up Here's the code: package lists; import bookdata.*; public class DoublyLinkedList { int size; //Variable que define el tamano de la lista. Node head, tail; //Nodos que definen el Head y Tail en la lista. //Constructor public DoublyLinkedList(){ this.head = null; this.tail = null; this.size = 0; } //Insert a new book in alphabetic order. public void insert(Book nb){ //Creamos uno nuevo nodo con el...

  • To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. t...

    To solve real world problem, the programer uses ADT like list, stack, queue, set, map, ... etc. to build our data model. In AS8, we pick and choose STL queue and stack to build a postfix calculator. In this assignment you are to Design your own linked-list, a series of integer nodes. The private attributes of this IntLinked Queue including a integer node struct and private control variables and methods: private: struct Node { int data; Node *next; }; Node...

  • (1) Implement the countKey(T element) method, which should return a count of the number of times...

    (1) Implement the countKey(T element) method, which should return a count of the number of times that the given key (the element) is found in the list. (2) Implement the indexOf(T element) method, which is similar as the indexOf method in the String class. It returns the index (the position starting from the head node) of the first occurrence of the given element, or -1, if the element does not occur in the list. You will need to track the...

  • Please help me on all the questions !!!!!!!! Really need help! Will give a thumb up...

    Please help me on all the questions !!!!!!!! Really need help! Will give a thumb up for helping. Short Answer (6) Explain why a public method should be declared to be final if it is called by a constructor. In the linked implementation of a list, why shouldn’t the constructor call the method clear even though they do the same exact assignment statements? Outline the basic steps to add a node to the end of a linked implementation of a...

  • Please help me on all the questions !!!!!!!! Really need help! Will give a thumb up...

    Please help me on all the questions !!!!!!!! Really need help! Will give a thumb up for helping. True/False (13) Chapter 14 - A List Implementation that Links Data Adding a node to an empty chain is the same as adding a node to the beginning of a chain. Adding a node at the end of a chain of n nodes is the same as adding a node at position n. You need a temporary variable to reference nodes as...

  • Java help: Please help complete the locate method that is in bold.. public class LinkedDoubleEndedList implements...

    Java help: Please help complete the locate method that is in bold.. public class LinkedDoubleEndedList implements DoubleEndedList { private Node front; // first node in list private Node rear; // last node in list private int size; // number of elements in list ////////////////////////////////////////////////// // YOU MUST IMPLEMENT THE LOCATE METHOD BELOW // ////////////////////////////////////////////////// /** * Returns the position of the node containing the given value, where * the front node is at position zero and the rear node is...

  • PYTHON -------------------------------------------------------- class LinkedList:    def __init__(self):        self.__head = None        self.__tail = None   

    PYTHON -------------------------------------------------------- class LinkedList:    def __init__(self):        self.__head = None        self.__tail = None        self.__size = 0    # Return the head element in the list    def getFirst(self):        if self.__size == 0:            return None        else:            return self.__head.element        # Return the last element in the list    def getLast(self):        if self.__size == 0:            return None        else:            return self.__tail.element    # Add an element to the beginning of the list    def addFirst(self, e):        newNode = Node(e) # Create a new node        newNode.next = self.__head # link...

  • ***Using C++ and also please label "a" and "c" accordingly. Thank you!!**** a) Write the member...

    ***Using C++ and also please label "a" and "c" accordingly. Thank you!!**** a) Write the member function void deleteNode() that will delete the first node from the linked list. b) Modify the LList to create a data member Node *cur that points to the current node. Write the following member functions: • void forward() that moves the cur pointer to the next node. • void backward() that moves the cur pointer to the previous node. • void delete() that removes...

  • Are based on the following Queue class code segment class QueueFull {/* Empty exception class */};...

    Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...

  • I need help filling in the the code in the methods add, multiply, and evaluate package...

    I need help filling in the the code in the methods add, multiply, and evaluate package poly; import java.io.IOException; import java.util.Scanner; /** * This class implements evaluate, add and multiply for polynomials. * * * */ public class Polynomial {       /**    * Reads a polynomial from an input stream (file or keyboard). The storage format    * of the polynomial is:    * <pre>    * <coeff> <degree>    * <coeff> <degree>    * ...    *...

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