Write a program that creates a linked list object of 10 characters and creates a second list object containing a copy of the first list, but in reverse order.

What will be an ideal response?


```
#include
using namespace std;

#include "List.h"

// function template that takes two List objects as arguments
// and makes a copy of the second argument reversed in the first argument.
template< typename T >
void reverseList( List< T > &first, List< T > &second )
{
List< T > temp( second ); // create a copy of second
T value; // variable to store removed item from temp

// loop through the list until it is empty
while ( !temp.isEmpty() )
{
temp.removeFromFront( value ); // remove value from temp list
first.insertAtFront( value ); // insert at beginning of first list
} // end while
} // end reverseList template function

int main()
{
List< char > list1;
List< char > list2;

// insert a - g onto list1
for ( char c = 'a'; c <= 'j'; c++ )
list1.insertAtBack( c );

list1.print(); // print list
reverseList( list2, list1 ); // call to function reverseList

cout << "The list after reversing:\n";
list2.print(); // print list
return 0; // indicates successful termination
} // end main
```
The list is: a b c d e f g h i j
All nodes destroyed
The list after reversing:
The list is: j i h g f e d c b a
Destroying nodes ...
j i h g f e d c b a
All nodes destroyed
Destroying nodes ...
a b c d e f g h i j
All nodes destroyed

Computer Science & Information Technology

You might also like to view...

Hotspots are defined through the use of ____ maps.

A. target B. image C. practice D. link

Computer Science & Information Technology

Define an exception class called FileNotFoundException.

The class should have a constructor with no parameters. If an exception is thrown with this zero-argument constructor, getMessage should return “File Not Found!” The class should also have a constructor with a single parameter of type String. If an exception is thrown with this constructor, then getMessage returns the value that was used as an argument to the constructor.

Computer Science & Information Technology

space/time trade-off in hashing

What will be an ideal response?

Computer Science & Information Technology

A tuple is an immutable sequence of items and does not have mutator methods.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology