Predict which sort rearranges the data in the following manner… Original Set: 7, 5, 1, 8, 9, 2, 6, 3, 4 First Iteration: 1, 5, 7, 8, 9, 2, 6, 3, 4 Second Iteration: 1, 2, 7, 8, 9, 5, 6, 3, 4 Third Iteration: 1, 2, 3, 8, 9, 5, 6, 7, 4 Forth Iteration: 1, 2, 3, 4, 9, 5, 6, 7, 8Fifth Iteration: 1, 2, 3, 4, 5, 9, 6, 7, 8 ….
Category: Uncategorized
The following code is an add() method for a linked list. As…
The following code is an add() method for a linked list. Assume the add() method were called for the numbers 1, 2, 3, 4, in that order. What would the list look like? void add(T num){ auto temp = make_shared< Node >(); temp->value = num; temp->next = nullptr; if(front == nullptr){ top = temp; end = temp; } else{ temp->next = front; front = temp; } }
Given a linked list with a front pointer to the first value…
Given a linked list with a front pointer to the first value in the list, and the list values are as the following values in a linked list… front->1, 2, 3, 4, 5, 6 What would the list look like after running the following code? auto temp1 = front->next->next; auto temp2 = temp1->next; temp1->next = temp2->next;
How would you create a child class DynamicBucket given the f…
How would you create a child class DynamicBucket given the following base class Bucket? template class Bucket{ public: Bucket(T data, bool filled = false):data(data), filled(filled){} T getData() { return data; } bool isFilled(){ return filled; } private: T data; bool filled; };
Given the two data types below, where are each allocated in…
Given the two data types below, where are each allocated in memory? int p1 = 7; int * p2 = new int[5];
Given a linked list with a front pointer to the first value…
Given a linked list with a front pointer to the first value in the list, and the list values are as the following values in a linked list… front->1, 2, 3, 4, 5, 6 What would the list look like after running the following code? auto curr = front; while(curr != nullptr){ cout value next->next; } *Watch out for the second line of code in the loop, it was intentional to have next in there twice.
Write a recursive C++ function called sumDigits(int n) that…
Write a recursive C++ function called sumDigits(int n) that takes a positive integer n as input and returns the sum of its digits. For example: sumDigits(123) should return 6 (1 + 2 + 3). sumDigits(9875) should return 29 (9 + 8 + 7 + 5). Here is an iterative version that you can use for reference on the logic. #include using namespace std; int sumOfDigits(int n) { int sum = 0; while (n != 0) { // Extract the last digit int last = n % 10; // Add last digit to sum sum += last; // Remove the last digit n /= 10; } return sum; } int main() { int n = 12345; cout
Which of the following is NOT a valid identifier declaration…
Which of the following is NOT a valid identifier declaration for the following class? template class Bucket{ public: Bucket(T data, bool filled = false):data(data), filled(filled){} T getData() { return data; } bool isFilled(){ return filled; } private: T data; bool filled; };
Given an object of Bucket b, which is the most useful way to…
Given an object of Bucket b, which is the most useful way to call the isFilled() method? class Bucket{ public: Bucket(int data, bool filled = false):data(data), filled(filled){} int getData() ; bool isFilled(); private: int data; bool filled; };
What is the keyword to declare a smart pointer to specify th…
What is the keyword to declare a smart pointer to specify that it will allocate the space for the item at run time?