Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

complete the missing code Hinclude prev - nullptr; } }; class DoublyLinkedList { public: DoublyLinkedListNode *head; DoublyLinkedListNode *tail; DoublyLinkedList() i this->head - nullptr; this tail

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

complete the missing code

Hinclude prev - nullptr; \} \}; class DoublyLinkedList \{ public: DoublyLinkedListNode *head; DoublyLinkedListNode *tail; DoublyLinkedList() i this->head - nullptr; this tail - nullptr; \} void insert_node(int node_data) i DoublyLinkedListNode* node - new DoublyLinkedListNode(node_data); if (!this-shead) i this->head - node; f else i this tail->next - node; node->prev - this->tail; \} this->tail - node; \} \} void print_doubly_linked_List(DoublyLinkedListNode* node, string sep, ofstreamz fout) \{ while (node) \{ fout data; node - node->next; if (node) \{ fout next; /* * Complete the 'reverse' function below. * * The function is expected to return an INTEGER_DOUBLY_LINKED_LIST. * The function accepts INTEGER_DOUBLY_LINKED_LIST llist as parameter. / / * For your reference: * DoublyLinkedListNode \{ * int data; * DoublyLinkedListNode* next; * DoublyLinkedListNode* prev; }; * / DoublyLinkedListNode* reverse(DoublyLinkedListNode* llist) \{ int main() \{ ofstream fout(getenv("OUTPUT_PATH")); int t; cin t; cin.ignore(numeric_limitsmax(), ); for (int titr=0;titr llist_count; cin.ignore(numeric_limitsmax(), ); for (int i=0;iinsert_node(llist_item); \} DoublyLinkedListNode llistl = reverse (llist > head ); print_doubly_linked_list(llist1, " ", fout); fout " "; free_doubly_linked_list(llist1); out.close (); eturn 0 ; Return a reference to the head node of the reversed list. Note: The head node might be NULL to indicate that the list is empty. Function Description Complete the reverse function in the editor below. reverse has the following parameter(s): - DoublyLinkedListNode head: a reference to the head of a DoublylinkedList Returns - DoublylinkedListNode: a reference to the head of the reversed list Input Format The first line contains an integer t, the number of test cases. Each test case is of the following format: - The first line contains an integer n, the number of elements in the linked list. - The next n lines contain an integer each denoting an element of the linked list. Constraints - 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

What aspects would it be impossible to capture?

Answered: 1 week ago

Question

Enhance your words with effective presentation aids

Answered: 1 week ago