1 C标准库 快排
void qsort(void *base, size_t num, size_t width, int (__cdecl *compare )(const void *elem1, const void *elem2 ) );
#include <stdlib.h>
#include <iostream.h>
int compare(const void *arg1, const void *arg2);
void main(void)
{
const int max_size = 10;
int num[max_size];
int n;
for (n = 0; cin >> num[n]; n ++);
qsort(num, n, sizeof(int), compare);
}
int compare(const void *arg1, const void *arg2)
{
return (*(int *)arg1 < *(int *)arg2) ? -1 :
(*(int *)arg1 > *(int *)arg2) ? 1 : 0;
}
std::sort(data, data + arraySize)
#include <algorithm>
3 split
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
vector<string> &split(const string &s, char delim, vector<string> &elems) {
stringstream ss(s);
string item;
while (getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
vector<string> split(const string &s, char delim) {
vector<string> elems;
split(s, delim, elems);
return elems;
}
int main()
{
string line;
while(getline(cin, line))
{
vector<string> elems = split(line, ',');
for(int i=0;i<elems.size();i++)
cout << elems[i] << endl;
}
}