Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Simulate a linear linked-list by an array Let L be a linear linked list. We will

ID: 3563425 • Letter: S

Question

Simulate a linear linked-list by an array

Let L be a linear linked list. We will use array A to represent L. Your task is to write a C++ program that simulates operations on L by using A, and outputs results.

The following is an example snapshot of L and A at some given time:

struct node {

   int data;

   int next;

};

struct node A[100] ;

Again, we assume that each node in L contains a distinct data value

Do the following operations on A:

HERE WE IMAGINE OPERATIONS ON L, BUT ACTUALLY DO THEM ON A

NEVER USE A[0]

THE next field in A[i] GIVES YOU THE SUCCESSOR NODE

YOU MAY USE ADDITIONAL VARIABLES FOR HEAD AND LAST NODES

YOU MAY USE -1 IN THE NEXT FIELD TO MARK THE FREE CELLS IN A, AND WHEN YOU NEED A CELL FOR NEW NODE YOU CAN USE THESE FREE CELLS

A y : Create a new node with data value y, and append this node to L

I x y : Find the node t with value x, create a new node p with data value y, and insert node p after t in L

D y : Find the node with data value y, and delete that node from L

R : Reverse L

T : Output all data values in L

Sample Input/Output:

A 5

A 1

I 5 4

I 1 9

A 7

I 9 8

D 9

D 8

T

5 4 1 7

R

T

7 1 4 5


head L: 0 never used not 5 assigned

Explanation / Answer

http://ge.tt/67iyOoz1/v/0

code with additional info :)