Reference no: EM132080039
You need help with these three questions. Please answer all of them
1. Draw a sketch of a doubly-linked list, specifically of class DLinkedList in DLinkedList.h, containing the first four words of your favorite song (one word in each node). Make sure to show the DLinkedList object, all node objects, and all objects' data members and pointers.
2. Complete the following main function to create your linked list above (Your code should go in only the indicated space - do not change any other code).
#include <iostream>
#include <string>
#include "DLinkedList.h"
using namespace std;
int main()
{
DLinkedList<string> lyrics;
// YOUR CODE TO CREATE THE LIST GOES HERE
cout << lyrics.front() << endl;
}
3. Write the following new member function for the DLinkedList class. The member function must swap the first and second data nodes (not the sentinels) in the linked list (other data nodes stay as they are). Throw an exception if the list has fewer than two elements. Your code should go in only the indicated space (in DLinkedList.h) - do not change any other code.
template <typename E>
void DLinkedList<E>::swapFirstAndSecond(){
// YOUR CODE TO SWAP NODES GOES HERE
}
Test that your code works by again printing out the front of the list in your main function after calling lyrics.swapFirstAndSecond().
Include a screen capture of the output of your program