Hello, I was given a task to implement a simply linked list on an array. I do not quite understand what is required of me. Implement stacks / decks / doubly-connected and single-linked lists / queues, etc. I can, operations to them, too, but using structures

struct list { string val = " "; list* next; } 

What should the implementation look like on an array?

  • If someone has questions on the implementation of the functions - write, I did everything - GenryLettem

2 answers 2

The array simply uses the index of the next element instead of the pointer to the next element. Those. your structure looks like

 struct list { string val; size_t next; } 

Accordingly, the header is simply size_t , equal to the index of the first element of the array, etc.

For example, the elements:

  0 1 2 3 "str1",1 "str2",3 "str4",0 "str3",2 

form a list of array elements 0 -> 1 -> 3 -> 2

    I will assume that the dynamic array means. That is, list items are actually stored in an array — a contiguous memory area. Because of this, you should not need pointers to the following elements next . It should be possible to add and remove items from anywhere in this array list. That, in turn, requires very fine work with dynamically allocated memory.