Question: using java 14) Create a singly linked list using only two variables: head and current. Traverse through the list void addToEnd (struct node *&head, int

14) Create a singly linked list using only two variables: head and current. Traverse through the list void addToEnd (struct node *&head, int data) //create node //if head==NULL //else int main() { node - head-NULL; addToEnd (head, 1); addToEnd (head, 2); addToEnd (head, 3); //Traverse using current void addToEnd (struct node *Ghead, int data) { node current; node *newNode - new node; // Sets it to actually point to something newNode->data-data; newNode->next = NULL; if (head) head-newNode: else { current-head; while (current->next ! - NULL) current -current->next; node* current;//has to be declared outside for (current-head; current->next !=NULL; current-current->next) coutdata; current->next-newNode; int main() node - head-NULL, addToEnd (head, 1); MacBook Pro Page next; node* current} //has to be declared outside for (current-head; current->next!-NULLcurrent current->next) coutdata; */ current->next-newNode; int main() node * head=NULL; addToEnd (head, 1); addToEnd (head, 2); addToEnd (head, 3); current-head; while (current ! - NULL coutdata; current = current->next; for (node* current-head) cout data, t-head: current 1-NULL; current-current->next) MacBook Pro 2 14) Create a singly linked list using only two variables: head and current. Traverse through the list void addToEnd (struct node *&head, int data) //create node //if head==NULL //else int main() { node - head-NULL; addToEnd (head, 1); addToEnd (head, 2); addToEnd (head, 3); //Traverse using current void addToEnd (struct node *Ghead, int data) { node current; node *newNode - new node; // Sets it to actually point to something newNode->data-data; newNode->next = NULL; if (head) head-newNode: else { current-head; while (current->next ! - NULL) current -current->next; node* current;//has to be declared outside for (current-head; current->next !=NULL; current-current->next) coutdata; current->next-newNode; int main() node - head-NULL, addToEnd (head, 1); MacBook Pro Page next; node* current} //has to be declared outside for (current-head; current->next!-NULLcurrent current->next) coutdata; */ current->next-newNode; int main() node * head=NULL; addToEnd (head, 1); addToEnd (head, 2); addToEnd (head, 3); current-head; while (current ! - NULL coutdata; current = current->next; for (node* current-head) cout data, t-head: current 1-NULL; current-current->next) MacBook Pro 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
