Write a C++ program which does following: Simulate an array by a linear linked l
ID: 3667350 • Letter: W
Question
Write a C++ program which does following:
Simulate an array by a linear linked list:
Let A be an array that stores up to n (n=100 here) integers. We will use a linked list L to represent A. Your task is to write a C++ program that simulates operations on A by using L, and outputs results.
The following is an example snapshot of L and A at some given time:
int A[8]; A[1]=5; A[3]=2; A[4]=1; A[6]=7
/* node definitions for L */
struct node {
int index;
int data;
node* next;
};
typedef node *link;
AGAIN ASSUME THAT THE LIST DOES NOT CONTAIN MORE THAN 100 ELEMENTS
Do the following operations on L (the operations are defined on A; we need to perform equivalent operations on L):
HERE WE IMAGINE OPERATIONS ON A, BUT ACTUALLY DO THEM ON L, AND ALL ELEMENTS IN THE LIST ARE DISTINCT
A i x : Set A[i]=x
T : Output all data values in A (only the final assigned value, other parts are not used in A)
R: Resets A. All elements are reset meaning that there is no data in A.
I: Increment by 1 all elements of A.
Sample input/output:
A 1 5
A 3 4
A 4 1
A 6 7
A 3 2
I
T
index: 1 value: 6
index: 3 value: 3
index: 4 value: 2
index: 6 value: 8
R
A has been reset
T
No data in A now
A 1 5
T
index: 1 value: 5