Concept explainers
Assume a linked list contains following integers: 7, 2, 9, 5, 8, 3, 15 and the pointer head is pointing to the first node of the list. What will be the value of variable a after the following statements are executed:
Node<int> *curNode=head;
int a;
while(curNode->getNext()!=NULL){
{
curNode=curNode->getNext();
}
a=curNode->getItem();
A. 15
B. 7
C. 49
D. 3
In the given Linked list, the pointer variable curNode initially points to the head of the linked list.
The while loop will execute until the last element of the linked list.
The statement curNode = curNode->getnext() retrieves the next element of the linked list and the pointer points to this node each time when the loop executes.
Finally the pointer curNode points to the last node with the help of the statement a = curNode->getItem();
Step by stepSolved in 2 steps
- C++The List class represents a linked list of dynamically allocated elements. The list has only one member variable head which is a pointer that leads to the first element. See the following code for the copy constructor to List. List (const List & list) { for (int i = 0; i <list.size (); i ++) { push_back (list [i]); } } What problems does the copy constructor have? Select one or more options: 1. List (const List & list) {} does not define a copy constructor. 2. The list parameter should not be constant. 3. The new elements will be added to the wrong list. 4. Copy becomes shallow rather than deep. 5. The copy will create dangling pointers. 6. Copying will create memory leaks. 7. The condition must be: i <size () 8. head is never initialized.arrow_forwardWith Head node or not? statement is: if(first->llink == first) output << "List is empty"; O a. It is a Doubly linked list without Head node. O b. It is a Doubly linked list with Head node.arrow_forwardstruct insert_at_back_of_sll { // Function takes a constant Book as a parameter, inserts that book at the // back of a singly linked list, and returns nothing. void operator()(const Book& book) { /// TO-DO (3) /// // Write the lines of code to insert "book" at the back of "my_sll". Since // the SLL has no size() function and no tail pointer, you must walk the // list looking for the last node. // // HINT: Do not attempt to insert after "my_sll.end()". // ///// END-T0-DO (3) ||||// } std::forward_list& my_sll; };arrow_forward
- Every time you write a non-const member function for a linked list, you should always think about if that function is preserving your class invariants. Group of answer choices A. True B. Falsearrow_forwardT/F: All Linked Lists must have head node.arrow_forwardPlease fill in the blanks from 26 to 78 in C. /*This program will print students’ information and remove students using linked list*/ #include<stdio.h> #include<stdlib.h> //Declare a struct student (node) with 5 members //each student node contains an ID, an age, graduation year, // 1 pointer points to the next student, and 1 pointer points to the previous student. struct student { int ID; int age; int classOf; struct student* next; struct student* prev; }; /* - This function takes the head pointer and iterates through the list to get all 3 integers needed from the user, and save it to our list - Update the pointer to point to the next node.*/ void scanLL(struct student* head) { while(head != NULL) //this condition makes sure the list is not at the end { printf("Lets fill in the information. Enter 3 integers for the student's ID, age, and graduation year: "); scanf("%i %i %i",&&head->ID, &head->age, &head->classOf); //in order: ID, age, graduation…arrow_forward
- Assume a linked list contains following integers: 7, 2, 9, 5, 8, 3, 15 and the pointer head is pointing to the first node of the list. What will be the value of variable a after the following statements are executed: Node<int> *curNode=head; Node<int> *aNode; int s; while(curNode!=NULL){ { aNode=curNode; curNode=curNode->getNext(); } s=aNode->getItem(); A. 15 B. 3 C. 7 D. 2arrow_forward• find_last(my_list, x): Takes two inputs: the first being a list and the second being any type. Returns the index of the last element of the list which is equal to the second input; if it cannot be found, returns None instead. >> find_last(['a', 'b', 'b', 'a'], 'b') 2 >>> ind = find_last(['a', 'b', 'b', 'a'], 'c') >>> print(ind) Nonearrow_forward1)Write a Java program which stores three values by using singly linked list.- Node class1. stuID, stuName, stuScore, //data fields2. constructor3. update and accessor methods- Singly linked list class which must has following methods:1. head, tail, size// data fields2. constructor3. update and accessor methodsa. getSize() //Returns the number of elements in the list.b. isEmpty( ) //Returns true if the list is empty, and false otherwise.c. getFirstStuID( ), getStuName( ), getFirstStuScore( )d. addFirst(stuID, stuName, stuScore)e. addLast(stuID, stuName, stuScore)f. removeFirst ( ) //Removes and returns the first element of the list.g. displayList( ) //Displays all elements of the list by traversing the linked list.- Test class – initialize a singly linked list instance. Test all methods of singly linked list class. 2. Write a Java program which stores three values by using doubly linked list.- Node class4. stuID, stuName, stuScore, //data fields5. constructor6. update and…arrow_forward
- LAB: Playlist (output linked list) Given main(), complete the SongNode class to include the function PrintSongInfo(). Then write the PrintPlaylist() function in main.cpp to print all songs in the playlist. DO NOT print the head node, which does not contain user-input values. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones Title: You Don't Own Me Length: 151 Artist: Lesley Gorearrow_forwardAssume a linked list contains following integers: 5, 2, 4, 6, 8, 3, 15 and the pointer head is pointing to the first node of the list. What will be the value of variable a after the following statements are executed: Node<int> *curNode=head; int a=0; while(curNode!=NULL){ a+=curNode->getItem(); curNode=curNode->getNext(); if(curNode!=NULL) curNode=curNode->getNext(); } A.32 B.43 C.19 D.18arrow_forwardstruct node{int num;node *next, *before;};start 18 27 36 45 54 63 The above-linked list is made of nodes of the type struct ex. Your task is now to Write a complete function code to a. Find the sum of all the values of the node in the linked list. b. Print the values in the linked list in reverse order. Use a temporary pointer temp for a and b. i dont need a full code just the list partarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education