INSTRUKSIES:   1. Die vraestel bestaan uit TWEE afde…

INSTRUKSIES:   1. Die vraestel bestaan uit TWEE afdelings:   AFDELING A Vraag 1: Literêre Teks Kinderspeletjies Totaal: 10 punte   AFDELING B  Vraag 2: Filmstudie Jou Romeo Totaal: 20 punte   GROOTTOTAAL: 30 TYD: 50 MINUTE + 10 MINUTE LEES TYD + 10 MINUTE TYD VIR INHANDIGING.   2. Beantwoord asseblief AL die vrae.   3. Die antwoorde wat jy verskaf in hierdie vraestel moet jou eie persoonlike werk wees en mag van geen ander bron gekopieer word nie.   4. Lees alle vrae noukeurig deur voordat jy dit beantwoord.   5. Die blou blokkie kan in ander “tabs” oopgemaak word om die teks te sien.   6. Relevante leestekens vir gebruik: ô ê ï ë é  

Write a function called removeFirstOf3 that removes the firs…

Write a function called removeFirstOf3 that removes the first value in successive groups of three from a list of integers, returning those values in their original order as a new list. For example if a variable called list1 stores these values: [3, 19, 7, 45, -2, 8, 6, 18, 42, 5] | | | | | | +——+ +——+ +——+ group group group Then the following call: LinkedList list2 = list1.removeFirstOf3(); Should result in list1 and list2 storing the following values: list1: {19, 7, -2, 8, 18, 42}list2: {3, 45, 6, 5} Notice that the values stored in list2 are the values that were the first value in each of the groups of three in the original list. When a list has one or two values at the end that are not part of a group of three, then the first of those values is removed and included in the new list, as with the value 5 in the example above. You are writing a member function for a linked list class defined as follows: struct ListNode { int data; // data stored in this node ListNode* next; // link to next node in the list }; class LinkedList { private: ListNode* front; public: }; You are writing a function that will become part of the LinkedList class. You may define private helper functions to solve this problem, but otherwise you may not assume that any particular functions are available. You are allowed to define your own variables of type ListNode*, but you may not construct any new nodes, and you may not use any auxiliary data structure to solve this problem (no array, vector, list, stack, queue, string, etc). You also may not change any data members of the nodes. You MUST solve this problem by rearranging the links of the list. Remember that you can access the member variables of any LinkedList, including a passed in one or newly created one, from inside the LinkedList class.

Write a function combineWith that could be added to the Set…

Write a function combineWith that could be added to the Set class from lecture. The function accepts a reference to another binary tree of integers as a parameter and combines the two trees into a new third tree which is returned. The new tree’s structure should be a union of the structures of the two original trees; it should have a node in any location where there was a node in either of the original trees (or both). The nodes of the new tree should store an integer indicating which of the original trees had a node at that position (1 if just the first tree had the node, 2 if just the second tree had the node, 3 if both trees had the node). For example, suppose Set variables t1 and t2 have been initialized and store the following trees: t1 t2 +—+ | 9 | +—+ / \ / \ +—+ +—+ | 6 | | 14| +—+ +—+ / \ \ / \ \ +—+ +—+ +—+ | 9 | | 2 | | 11| +—+ +—+ +—+ / / +—+ | 4 | +—+ +—+ | 0 | +—+ / \ / \ +—+ +—+ | -3| | 8 | +—+ +—+ / / \ / / \ +—+ +—+ +—+ | 8 | | 5 | | 6 | +—+ +—+ +—+ \ \ +—+ | 1 | +—+ Then the following call: Set t3 = t1.combineWith(t2); will return the following tree: t3 +—+ | 3 | +—+ / \ / \ +—+ +—+ | 3 | | 3 | +—+ +—+ / \ / \ / \ / \ +—+ +—+ +—+ +—+ | 3 | | 1 | | 2 | | 3 | +—+ +—+ +—+ +—+ / \ / \ +—+ +—+ | 1 | | 2 | +—+ +—+ You are writing a public function for a binary tree class defined as follows: struct TreeNode { int data; // data stored in this node TreeNode* left; // reference to left subtree TreeNode* right; // reference to right subtree }; class Set { private: TreeNode* overallRoot; public: }; You are writing a function that will become part of the Set class from lecture. You may define private helper functions to solve this problem, but otherwise you may not call any other functions of the class. You may not construct any extra data structures to solve this problem. Remember that you can access the member variables of any Set, including a passed in one or newly created one, from inside the Set class.

CS 199 (133) Final Cheat Sheet for (initialization; test; up…

CS 199 (133) Final Cheat Sheet for (initialization; test; update) { statement(s); … } if (test) { statement(s); } else if (test) { statement(s); } else { statement(s); } while (condition) { statement(s); } type name(parameters) { statement(s); … return expression; } Math Description fabs(value) absolute value sqrt(value) square root round(value) Rounds to the nearest whole number pow(b, e) base to the exponent power   User Input Description getline(cin, variable) reads an entire line of input as a string and stores in variable cin >> variable reads a single token and stores in variable as whatever type variable is declared as   Random Description rand() random integer from 0 to max number srand(time(0)) Seeds random with the current time   Strings String function name Description string(1, chr) converts a character into a string s.append(str) Adds str onto the end of s s.erase(index, length) Removes length number of characters starting at index s.find(str) s.rfind(str) Returns the starting position of str in s (first occurrence for find, last for rfind). Returns string::npos otherwise. s.insert(index, str) Inserts str into s starting at index s.length()  or  s.size() Returns the number of characters in s s.replace(index, len, str) Replaces length characters starting with the character at index with str. s.substr(start, length)  or s.substr(start) Returns a substring of s. Does not alter s.   Character Function Description tolower(ch1) Returns ch1 in lowercase toupper(ch1) Returns ch1 in uppercase isalnum(ch1) Returns true if ch1 is alphanumeric isalpha(ch1) Returns true if ch1 is alphabetic isdigit(ch1) Returns true if ch1 is a decimal digit islower(ch1) Returns true if ch1 is a lowercase letter ispunct(ch1) Returns true if ch1 is a punctuation character isspace(ch1) Returns true if ch1 is white-space isupper(ch1) Returns true if ch1 is an uppercase letter   Streams Stream function Description f.clear(); resets stream’s error state, if any f.close(); stops reading file f.eof() returns true if stream is past end-of-file (EOF) f.fail() returns true if the last read call failed (e.g. EOF) f.good() returns true if the file exists f.get() reads and returns one character f.open(“filename”);f.open(s.c_str()); opens file represented by given C string (may need to write .c_str() if a C++ string is passed) f.unget(ch) un-reads one character f >> var reads data from input file into a variable (like cin);reads one whitespace-separated token at a time getline(f&, s&) reads line of input into a string by reference;returns a true/false indicator of success   Vectors vector member functions Description v.push_back(value); appends value at end of vector v.pop_back(); removes the value at the end of the vector v.clear(); removes all elements v[i] or get(i) returns a reference to the value at given index, get throws an exception if i is out of bounds, [] doesn’t v.insert(iterator, value); inserts given value at the index the iterator points to v.empty() returns true if the vector contains no elements v.erase(start, stop); removes values from start iterator position (inclusive) to stop iterator (exclusive) v[i] = value;  replaces value at given index v.size() returns the number of elements in vector v.begin() returns an iterator pointing to the beginning v.end(); returns an iterator pointing to the end v.cbegin(); returns a const iterator pointing to the beginning v.cend(); returns a const iterator pointing to the end v.rbegin(); returns an iterator pointing to the beginning that moves backwards v.rend() returns an iterator pointing to the end that moves backwards   Stacks s.empty() returns true if stack has no elements s.top() returns top value without removing it s.pop() removes top value; does NOT return anything; s.push(value); places given value on top of stack s.size() returns number of elements in stack Queues q.pop() removes front value; does NOT return anything q.push(value); places given value at back of queue q.empty() returns true if queue has no elements q.front() returns front value without removing q.back() returns back value without removing (not a traditional queue operation – don’t use) q.size() returns number of elements in queue Sets Member Description s.insert(value); adds given value to set s.clear(); removes all elements of set s.count(value) returns 1 if the value is in the set, 0 otherwise s.empty() true if set contains no elements s.erase(value); removes given value from set s.size() number of elements in set s.begin() returns an iterator pointing to the beginning s.end() returns an iterator pointing to the end Maps Member Description m.clear(); removes all key/value pairs m.find(key) an iterator pointing to the element, m.end()if not found m[key]  or m.at(key) returns value mapped to given key; if not found, [] adds it with a default value, .at throws an exception m.empty() true if the map contains no pairs m[key] = value; adds a key/value pair; if key already exists, replaces its value m.erase(key); or m.erase(iterator); removes any pair for given key or any pair pointed at by the iterator m.count() returns number of pairs in map m.begin() returns an iterator pointing to the first element m.end() returns an iterator pointing to one after the last element  

Recall the implementation of a priority queue using a vertic…

Recall the implementation of a priority queue using a vertically-ordered tree called a heap. Recall that the heap structure “bubbles” elements up and down as they are added and removed to maintain its vertical ordering. Given the following string/priority pairs: a:9, b:2, c:5, d:6, e:0, f:7, g:1, h:4, i:3, j:8 a) Write the final array representation of the binary heap that results when all of the above elements are pushed (added in the given order) with the given priorities shown to an initially empty heap. This is a “minheap”, that is, priorities with lesser integer values are higher in the tree. Write your answer in the following format: {a:17, b:63, c:40} [afterAdd] b) After adding all the elements, perform 2 pop operations (remove-min operations) on the heap. Write the final array representation of the heap that results after the two elements are removed, in the same format. [afterRemove]