Description Ex2. Remove negatives (35 points) Write the DLList member function DLList rmv_ret_negative(). which should r
Posted: Thu May 05, 2022 1:00 pm
I have 2 functions, the assignment for a doubly linked list, I want the solution on C++
Description Ex2. Remove negatives (35 points) Write the DLList member function DLList rmv_ret_negative(). which should remove nodes with negative values from the original list, add them to another temporary list, and return that list. Example: If the list list1 has [18, -5, -2, 20, 96, -25, 58] then after calling: listl.r_rel_get() list1 should contain [18, 28, 90, 50) The function should also return the list L-5, -2, -25] C dll.h Gmain.cpp + /home/main.cpp Spaces: 2 (Auto) Console Terminal Gmain.cpp dll.h 1 include "dll.h" 2 #include <iostream> 3 using std::string; 4 using std::to_string; 5 using std::cout; 6 using std::endl; 7 8 template <class T> 9 int replaceVal(DLList<T> &list, T f, Tr) { 10 11 if(list.is empty()) { 12 throw string("Error List is empty"); 13 } 14 15 int cuunt -0; 16 DLList<T>list1; DLLNode<T> *temp = list.head_node (); while(temp 1-nullptr){ if(temp->get_val() == f) { List1.add_to_head (r); count++; }else{ 59925NAK 17 18 19 20 21 22 23 24 > listl.add_to_head (temp->get_val()); } tomo temn sunt next(). All change Run
Description Ex3. Insertion (35 points) Write the PLList member function insert_before_after (T val, T insertVal, int c), which looks for the first occurrence of the value val in the list, if it is found it inserts insertval by the amount of c before and after val in the list. You are not allowed to declare and use an extra (temporary) data structure in your implementation. Example: If the list List1 has [8, 6, 16, 25, 28, 98, 25, 36) then calling: listl.insert_before_after (58, 4, 3); will not cause any change to the original list since the value 50 is not in the list. insert before after (29, 4, 8); would change the list to: [ 8, 6, 10, 4, 4, 4, 25, 4, 4, 4, 20, 90, 25, 55] Gmain.cpp + /home/main.cpp Spaces: 2 (Auto) Console Terminal C-main.cpp dll.h 1 #include "dll.h". 2 #include <iostream> 3 using std::string; 4 using std::to_string; 5 using std::cout; 6 using std::endl; 7 8 Lemplate <class T> 9 int replaceval(DLList<T> &list, T f, Tr) { 18 11 if(list.is_empty()) { 12 throw string("Error List is empty"); 13 } 14 15 int count = 0; 16 DLList<T> list1; 17 DLLNode<T> *temp-list.head_node(); 18 while (temp =nullptr){ 19 if(temp->get_val()==f)( 28 listl.add_to_head (r); 21 cuunt 22 Jelse{ 25 list1.add_to_head (temp->get_val()); 3 All changes ▶ Run
Description Ex2. Remove negatives (35 points) Write the DLList member function DLList rmv_ret_negative(). which should remove nodes with negative values from the original list, add them to another temporary list, and return that list. Example: If the list list1 has [18, -5, -2, 20, 96, -25, 58] then after calling: listl.r_rel_get() list1 should contain [18, 28, 90, 50) The function should also return the list L-5, -2, -25] C dll.h Gmain.cpp + /home/main.cpp Spaces: 2 (Auto) Console Terminal Gmain.cpp dll.h 1 include "dll.h" 2 #include <iostream> 3 using std::string; 4 using std::to_string; 5 using std::cout; 6 using std::endl; 7 8 template <class T> 9 int replaceVal(DLList<T> &list, T f, Tr) { 10 11 if(list.is empty()) { 12 throw string("Error List is empty"); 13 } 14 15 int cuunt -0; 16 DLList<T>list1; DLLNode<T> *temp = list.head_node (); while(temp 1-nullptr){ if(temp->get_val() == f) { List1.add_to_head (r); count++; }else{ 59925NAK 17 18 19 20 21 22 23 24 > listl.add_to_head (temp->get_val()); } tomo temn sunt next(). All change Run
Description Ex3. Insertion (35 points) Write the PLList member function insert_before_after (T val, T insertVal, int c), which looks for the first occurrence of the value val in the list, if it is found it inserts insertval by the amount of c before and after val in the list. You are not allowed to declare and use an extra (temporary) data structure in your implementation. Example: If the list List1 has [8, 6, 16, 25, 28, 98, 25, 36) then calling: listl.insert_before_after (58, 4, 3); will not cause any change to the original list since the value 50 is not in the list. insert before after (29, 4, 8); would change the list to: [ 8, 6, 10, 4, 4, 4, 25, 4, 4, 4, 20, 90, 25, 55] Gmain.cpp + /home/main.cpp Spaces: 2 (Auto) Console Terminal C-main.cpp dll.h 1 #include "dll.h". 2 #include <iostream> 3 using std::string; 4 using std::to_string; 5 using std::cout; 6 using std::endl; 7 8 Lemplate <class T> 9 int replaceval(DLList<T> &list, T f, Tr) { 18 11 if(list.is_empty()) { 12 throw string("Error List is empty"); 13 } 14 15 int count = 0; 16 DLList<T> list1; 17 DLLNode<T> *temp-list.head_node(); 18 while (temp =nullptr){ 19 if(temp->get_val()==f)( 28 listl.add_to_head (r); 21 cuunt 22 Jelse{ 25 list1.add_to_head (temp->get_val()); 3 All changes ▶ Run