Answered step by step
Verified Expert Solution
Question
1 Approved Answer
12. (10%) Fill in the five blanks (A, B, ..., E) in the following C++ function, Reverse(), which reverses a singly linked list (or called
12. (10%) Fill in the five blanks (A, B, ..., E) in the following C++ function, Reverse(), which reverses a singly linked list (or called a Chain in the program code). For example, after running X.Reverse() where X=(x1, X2, Xn) is a chain, X will become (Xn, Xn-1, ..., x1). // Declaration of a node (in a chain). template class ChainNode { friend class Chain ; private: T data; ChainNode* link; // "link" points to the next node in the chain. // "link" of the last node is set to be NULL. }; Il Declaration of a chain. template class Chain { private: ChainNode *first; // 'first points to the 1st node in the chain. public: Chain(void) {first = last = NULL;}; // constructor void Chain::Reverse(void); // The function. }; // This is the function used for reversing the chain. // In other words, it turns a chain (X1, X2, ..., xn) into (Xn, Xn-, ..., x). template void Chain::Reverse(void) { ChainNode *next = first, *current = NULL; while (next) { ChainNode *previous = ; current = _B__; next = current->link D } first = E }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started