Psl67/recursion templates

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา

findmax

#include <iostream>
#include <vector>

using namespace std;

int n;
vector<int> x;

void read_input()
{
  cin >> n;
  for(int i = 0; i < n; i++) {
    int xx;
    cin >> xx;
    x.push_back(xx);
  }
}

int find_max(vector<int>& x, int n)
{
  // TODO: write this function, do not use any loop control
}

int main()
{
  read_input();
  cout << find_max(x,n) << endl;
}

selection sort

#include <iostream>
#include <vector>

using namespace std;

int n;
vector<int> x;

void read_input()
{
  cin >> n;
  for(int i = 0; i < n; i++) {
    int xx;
    cin >> xx;
    x.push_back(xx);
  }
}

int find_max_index(vector<int>& x, int n)
{
  // TODO: return the index of the maximum element in x[0], x[1],... x[n-1]
  //       don't use any loop control structures
}

void swap(int& x, int& y)
{
  int t = x;
  x = y;
  y = t;
}

void selection_sort(vector<int>& x, int n)
{
  // TODO: don't use any loop control structures
}

int main()
{
  read_input();
  selection_sort(x, n);
  for(int i=0; i<n; i++) {
    cout << x[i] << endl;
  }
}