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

Please answer all questions. Thank you. Part I: array_based list A. The followin

ID: 3728023 • Letter: P

Question

Please answer all questions. Thank you.


Part I: array_based list A. The following declaration is for problem 1 and 2: const int MAX=10; class AList public: Chain0: void PrintAIO void Delete(int k, int&x;,bool &success;); delete element at the position with index k and save it in x void Insert(int k, int x, bool &success;); ll insert element x at the position with index k private: int list[MAX] int size; AList Chain; bool flag; int y; Assume you have a list of integers stored in a array-based list with the name of Chain declared as above and has the following integers 1. 10 12 18 21 Show the contents of Chain and the value of flag after you execute each statement of the following program segment: Chain::Insert(2, 6, flag); Chain::Insert(9, 25, flag); Chain::Delete(0, y, flag); Chain::Delete(8, y, flag); Assume you have a list of integers stored in an array-based list with the class name AList declared as above. Write the PrintAllO method for the AList class to prints out all values in the list that are greater than 10. 2. B. With the following declaration, do problem 1&2: const int MAX-10; class AListf public : Chain0:

Explanation / Answer

PART II:Linked List

A)

1)object.member(Dot operator use to access the member of the object)
pointer->member(Arrow operator used to access the member of the refeering node of the pointer)

As given that head is a pointer to the first node. so head.data will give the error. To obtain the correct result we have to use head->data.

Similarly,head.next.data will also give the error.

2)

Head:-Pointer to the first node.

Therefore ,we can access 20 as follows:

Head->data

we can 32 as follows:

Head->next->next->data

B)

2)/* Node of a doubly linked list */
struct Node
{
int data;
struct Node *next; // Pointer to next node in Doubly linked List
struct Node *prev; // Pointer to previous node in Doubly linked list
};

void addAtEnd(struct Node** head, int data)//head is pointer to teh first node and data is the data of the new node

{

struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));

struct Node *last = *head;

new_node->data = data;

new_node->next = NULL;

if (*head == NULL)

{

new_node->prev = NULL;

*head = new_node;

return;

}

while (last->next != NULL)

last = last->next;

last->next = new_node;

new_node->prev = last;

return;

}

3)

void addAtStart(struct Node** head, int data)

{

struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));

new_node->data = data;

new_node->next = (*head);

new_node->prev = NULL;

if((*head) != NULL)

(*head)->prev = new_node ;

(*head) = new_node;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote