EDN Admin
Well-known member
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue can some one please help me i am not sure what to do. :/
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue <br/>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue #include<span style="font-size:9.5pt; font-family:Consolas
<span style="color:#A31515 <iostream>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue #include<span style="font-size:9.5pt; font-family:Consolas
<span style="color:#A31515 <vector>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue using<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue namespace std;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas median(vector<T> & v,
<span style="color:blue int size);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue void<span style="font-size:9.5pt; font-family:Consolas sort(vector<T> & v,
<span style="color:blue int number_used);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas index_of_smallest(vector<T> & v,
<span style="color:blue int start_index, <span style="color:blue int number_used);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue void<span style="font-size:9.5pt; font-family:Consolas swap_values(T& num1, T& num2);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas main()
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int n;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas vector<<span style="color:blue int> v;
<span style="color:green // declaration of the vector
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:green //getting number of values from user
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Enter n: ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cin >> n;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Enter " << n << <span style="color:#A31515
" integer values: ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:green //putting the different numbers given by the user into the vector
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for(<span style="color:blue int i = 0; i < n; i++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int x;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cin>>x;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas v.push_back(x);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:green //showing the user what they put in
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Values entered: ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for(<span style="color:blue int i =0; i < n; i++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout << v <<
<span style="color:#A31515 " , ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "n";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Sorted values: ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas sort(v, n);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for(<span style="color:blue int i =0; i < n; i++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout << v <<
<span style="color:#A31515 " , ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "n";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int size;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int median;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; text-decoration:underline
median(v,size); // error right here
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Median = ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue return 0;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue void<span style="font-size:9.5pt; font-family:Consolas sort(vector<T> & v,
<span style="color:blue int number_used )
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int index_of_next_smallest;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for (<span style="color:blue int index = 0; index < number_used - 1; index++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas index_of_next_smallest =
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas index_of_smallest(v, index, number_used);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas swap_values(v[index], v[index_of_next_smallest]);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue void<span style="font-size:9.5pt; font-family:Consolas swap_values(T& num1, T& num2)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas T temp;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas temp = num1;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas num1 = num2;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas num2 = temp;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas index_of_smallest(vector<T> & v,
<span style="color:blue int start_index, <span style="color:blue int number_used)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue double min = v[start_index];
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int index_of_min = start_index;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for (<span style="color:blue int index = start_index + 1; index < number_used; index++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue if (v[index] < min)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas min = v[index];
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas index_of_min = index;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue return index_of_min;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas median(vector<T> & v,
<span style="color:blue int size)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas size = v.size();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas T medianValue;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas sort(v, number_used);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue if(size % 2 ==0)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas medianValue = (v[size / 2 - 1] + v[size / 2])/2;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue else
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas medianValue = v[size / 2];
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue return medianValue;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
View the full article
<span style="font-size:9.5pt; font-family:Consolas; color:blue can some one please help me i am not sure what to do. :/
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue <br/>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue #include<span style="font-size:9.5pt; font-family:Consolas
<span style="color:#A31515 <iostream>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue #include<span style="font-size:9.5pt; font-family:Consolas
<span style="color:#A31515 <vector>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue using<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue namespace std;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas median(vector<T> & v,
<span style="color:blue int size);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue void<span style="font-size:9.5pt; font-family:Consolas sort(vector<T> & v,
<span style="color:blue int number_used);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas index_of_smallest(vector<T> & v,
<span style="color:blue int start_index, <span style="color:blue int number_used);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue void<span style="font-size:9.5pt; font-family:Consolas swap_values(T& num1, T& num2);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas main()
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int n;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas vector<<span style="color:blue int> v;
<span style="color:green // declaration of the vector
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:green //getting number of values from user
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Enter n: ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cin >> n;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Enter " << n << <span style="color:#A31515
" integer values: ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:green //putting the different numbers given by the user into the vector
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for(<span style="color:blue int i = 0; i < n; i++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int x;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cin>>x;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas v.push_back(x);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:green //showing the user what they put in
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Values entered: ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for(<span style="color:blue int i =0; i < n; i++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout << v <<
<span style="color:#A31515 " , ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "n";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Sorted values: ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas sort(v, n);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for(<span style="color:blue int i =0; i < n; i++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout << v <<
<span style="color:#A31515 " , ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "n";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int size;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int median;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; text-decoration:underline
median(v,size); // error right here
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas cout <<
<span style="color:#A31515 "Median = ";
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue return 0;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue void<span style="font-size:9.5pt; font-family:Consolas sort(vector<T> & v,
<span style="color:blue int number_used )
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int index_of_next_smallest;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for (<span style="color:blue int index = 0; index < number_used - 1; index++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas index_of_next_smallest =
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas index_of_smallest(v, index, number_used);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas swap_values(v[index], v[index_of_next_smallest]);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue void<span style="font-size:9.5pt; font-family:Consolas swap_values(T& num1, T& num2)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas T temp;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas temp = num1;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas num1 = num2;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas num2 = temp;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas index_of_smallest(vector<T> & v,
<span style="color:blue int start_index, <span style="color:blue int number_used)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue double min = v[start_index];
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue int index_of_min = start_index;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue for (<span style="color:blue int index = start_index + 1; index < number_used; index++)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue if (v[index] < min)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas min = v[index];
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas index_of_min = index;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue return index_of_min;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue template<span style="font-size:9.5pt; font-family:Consolas <<span style="color:blue typename T>
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue int<span style="font-size:9.5pt; font-family:Consolas median(vector<T> & v,
<span style="color:blue int size)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas size = v.size();
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas T medianValue;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas sort(v, number_used);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue if(size % 2 ==0)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas medianValue = (v[size / 2 - 1] + v[size / 2])/2;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue else
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas medianValue = v[size / 2];
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue return medianValue;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
View the full article