Question: CIS 251 Homework 6 Linked Array To get some more practice with linked list, we will implement a linked structure that simulates an array. We
CIS 251 Homework 6 Linked Array
To get some more practice with linked list, we will implement a linked structure that simulates an array. We will then use that structure to step through an array in different ways. So you will have two files, array.h (implementation file for the array class) and Homework 6.cpp (an application described on the back of the assignment).
Here are the declarations that will be used:
struct array_node
{
int contents;
array_node* next;
};
typedef array_node* array_ptr;
class array
{
private:
array_ptr front;
public:
array (int n);
void set (int index, int number);
int get (int index);
};
Define the functions:
// Constructor that creates a list of n elements
// (uninitialized contents).
array (int n);
// Sets the given index value (first element in the // list is index 0) to number.
void set (int index, int number);
// Returns the value at the given index (first
// element in the list is index 0).
int get (int index);
In the Homework 6.cpp application file, declare an array with size (value entered by the user) elements and write loops to accomplish the following tasks.
The tasks to accomplish are:
Write a loop to place random numbers from 1 to 100 in the array.
Write a loop to print the elements of the array with spaces between.
Write a loop to print the elements in reverse order.
Write a loop to print every second element.
Write a loop to print every nth element.
Note that you are using an array-like structure in the application. You will not be referencing any pointers or array indexes with [ ]. You will be using the constructor and the set and get member functions.
A sample output might be:
Enter the size of the array: 15
The array in forward direction is:
81 56 41 43 58 58 100 71 26 22 79 21 32 4 71
The array in reverse direction is:
71 4 32 21 79 22 26 71 100 58 58 43 41 56 81
Every second element of the array is:
81 41 58 100 26 79 32 71
Enter an array step: 5
Every nth element of the array is:
81 58 79
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
