This function will sort a vector so that the negative number are sorted from smallest to largest, and the positive numbers are sorted from largest to smallest. If v is: //-23 -3 -21 -17 -7 -39 -43 -37 -18 -41 -31 -40 -37 12 7 7 41 12 5 39 //it would look like this when the function is done //-43 -41 -40 -39 -37 -37 -31 -23 -21 -18 -17 -7 -3 41 39 12 12 7 7 5 //Note you can assume that v is separated and mid is either the last negative number or the first positive number // Input v is a separated list of numbers //Output v with its positive and negative parts sorted void my_sort(std::vector & v,int mid); //)This function will separate the vector so all the negative numbers and zero are on the left and the positive numbers are on the right. If v is: //-37 -3 -21 5 -7 -39 -43 -37 41 7 12 -40 -31 -41 -18 7 -17 12 -23 39 //it leave like this //-23 -3 -21 -17 -7 -39 -43 -37 -18 -41 -31 -40 -37 12 7 7 41 12 5 39 // Input v is the vector of numbers //Output v with all the negative numbers are on the left, and the positive numbers are on the right. It returns the position of the last negative number or the position of the first positive number //What is the running time of your function when n is the length of the vector int sep(std::vector & v); //()This is a RECURSIVE function that makes a vector of random integers between the number -50 to 50 inclusive. // Input a vector to be filled and the length of the vector // Output a random vector void fill_vector(std::vector & v, int len); //This function will find all the absolute numbers that are in both the negative and positive parts of a vector and put those numbers into merge_v. If s is: //-43 -41 -40 -39 -37 -37 -31 -23 -21 -18 -17 -7 -3 41 39 12 12 7 7 5 //then merge_v would be //41 39 7. // Input v with all the negative numbers are on the left, and the positive number are on the right. Mid is the position of the last negative number or the position of the first positive number // Output merge_v an ordered list of the absolute numbers in v that are in both the negative and positive parts. //What is the running time of your function when n is the length of the vector void neg_pos(std::vector & v,int mid, std::vector & merge_v); //This is a RECURSIVE function that will print the sum of negative and position numbers //if v is // -43 -41 -40 -39 -37 -37 -31 -23 -21 -18 -17 -7 -3 41 39 12 12 7 7 5 //then the function would print //Sum of positive numbers is: -357 //Sum of negitive numbers is: 123 //Input v is an int vector //Output None void pos_neg_count(const std::vector & v) ;
[10/02, 11:59 am] Simran: #include #include #include #include [10/02, 11:59 am] Simran: int main(){ srand(time(0)); int len; std::cout << "Enter in a length of the vector: " << std::endl; std::cin >> len; std::vector v; fill_vector(v,len); std::cout << "Original list:" << std::endl; print_vector(v); int mid = sep(v); std::cout << "Separated list:" << std::endl; print_vector(v); my_sort(v,mid); std::cout << "Sorted list:" << std::endl; print_vector(v); pos_neg_count(v); std::vector merge_v; neg_pos(v,mid,merge_v); std::cout << "Merged list:" << std::endl; print_vector(merge_v); return 0; } Sample the program running. Enter in a length of the vector: 20 Original list: 49 -31 -41 7 47 45 40 -29 0 47 -26 22 4 -10 40 20 -19 -45 16 -47 Separated list: -47 -31 -41 -45 -19 -10 -26 -29 0 49 47 22 4 40 40 20 45 47 16 7 Sorted list: -47 -45 -41 -31 -29 -26 -19 -10 0 49 47 47 45 40 40 22 20 16 7 4 Sum of positive numbers is: -248 Sum of negitive numbers is: 337 Merged list: 47 45