Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 1.81 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. void my_swap(int & a, int & b){
  7.     int temp =  b;
  8.     b = a;
  9.     a = temp;
  10. }
  11.  
  12.  
  13. //find min value
  14. //int find_min(const vector<int> &v, const int & left, const int & right)
  15. int find_min(const vector<int> & v, const int & left, const int & right){
  16.     int smallestAmt = v[left];
  17.         for(size_t i = left; i <= v.size()-1; ++i){
  18.             //first if checks others when exception is made
  19.             if(v[left] > v[i]){
  20.                 smallestAmt = v[i];
  21.                     //start looping with new value
  22.                     for(size_t i = smallestAmt; i <= v.size()-1; ++i){
  23.                             //second exception made; only three can be made total
  24.                         if(v[smallestAmt] > v[i]){
  25.                             smallestAmt = v[i];
  26.                                 //loop again
  27.                             for(size_t i = smallestAmt; i <= v.size()-1; ++i){
  28.                                 if(v[smallestAmt] > v[i]){
  29.                                     smallestAmt = i;
  30.                                     return smallestAmt;
  31.                                 }
  32.  
  33.                             }
  34.                                 //third
  35.                             return smallestAmt;
  36.                         }
  37.                     }
  38.                         //second
  39.                     return smallestAmt;
  40.                 }
  41.         }
  42.         //if first; or if the starting value is the smallest
  43.     cout << "Smallest is " << smallestAmt;
  44.     return smallestAmt;
  45. }
  46.  
  47. void selection_sort(vector<int> & v){
  48.  
  49. }
  50.  
  51.  
  52. int main()
  53. {
  54.     //ze vectorz
  55.     vector<int>v;
  56.     v.push_back(3);
  57.     v.push_back(1);
  58.     v.push_back(4);
  59.     v.push_back(2);
  60.     cout << find_min(v, 2, v.size());
  61.  
  62.     return 0;
  63. }