Part1: Write an algorithm for the add method that will add at the end of the lin
ID: 3655538 • Letter: P
Question
Part1: Write an algorithm for the add method that will add at the end of the linked list instead of the beginning. What is the time complexity of this algorithm? (Below is my algorithm, not sure if it is correct) public void addEnd(T t){ Node tail = new Node (t) while(temp != null){ temp = temp.next;} temp.next = tail; temp = temp.next;} The time complexity for this algorithm is O(n). Part2:Modify the algorithm from the previous so that it makes use of a rear reference. How does this affect the time complexity of this and the other operations? Need help with this partExplanation / Answer
int addNodeBottom(int val, node *head) { node *current = head; node *newNode = (node *) malloc(sizeof(node)); if (newNode == NULL) { printf("malloc failed "); exit(-1); } newNode->value = val; newNode->next = NULL; while (current->next) { current = current->next; } current->next = newNode; return 0; }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.