Modify our Doubly Linked List code to include following index (rank) based acces
ID: 3604633 • Letter: M
Question
Modify our Doubly Linked List code to include following index (rank) based access operations
int RetrieveAt(int index)
void DeleteAt(int index)
void Swap(int index, int index)
index starts at 0 (just like array's subscript)
If the index is out of bound, RetrieveAt returns -999, DeleteAt does nothing, do nothing in Swap.
Write your own testing program to test the modified class
__________________________________________________________________DLinkeList.h_________________________________________________________
____________________________________________________________________________________________________________________________________
____________________________________________________________________DLinkedList.cpp____________________________________________________
____________________________________________________________________________________________________________________________________
Explanation / Answer
Hi, Please find my implementation for int RetrieveAt(int index) method.
Since you have mentioned that to do nothing for other two methods, so I have not implemented other methods.
int RetrieveAt(int index) {
if(index >= length || index < 0) {
return -999;
}
Node *temp = head;
int count = 0;
while(count < index) {
temp = temp->next;
count++;
}
return temp->data;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.