20170812
来源:互联网 发布:中经商品交易中心软件 编辑:程序博客网 时间:2024/05/16 06:59
/********************************************************//* sort排序 *//********************************************************///#include<iostream>//#include<vector>//#include<algorithm>//using namespace std;//int main()//{// vector<int>v;// v.push_back(13);// v.push_back(23);// v.push_back(03);// v.push_back(233);// v.push_back(113);// sort(v.begin(), v.end());// for (auto s : v)// cout << s <<endl;// system("pause");// return 0;//}/********************************************************//* 从大到小sort排序 *//********************************************************///#include<iostream>//#include<vector>//#include<algorithm>//#include <functional> //greater等仿函数的头文件//using namespace std;////bool SortFunction(int a, int b)//{// return a > b;//}//int main()//{// vector<int>v;// v.push_back(13);// v.push_back(23);// v.push_back(3);// v.push_back(233);// v.push_back(113);// //sort(v.begin(), v.end(),SortFunction);// sort(v.begin(), v.end(),greater<int>());// for (auto s : v)// cout << s <<endl;// system("pause");// return 0;//}/********************************************************//* 对结构体成员排序 *//********************************************************///#include <iostream>//#include <vector>//#include <algorithm>////using namespace std;//////struct Test//{// int a, b;//}TT;//////重写排序函数,从大到小排序//bool SortFunction(Test a, Test b)//{// return a.a > b.a;//}//////重载运算符 输出结构体数据//ostream& operator << (ostream &os, Test&tt)//{// os << tt.a << endl;// return os;//}//int main()//{// //测试迭代器// vector<int> as;// vector<int>::iterator ast;// for (int i = 0; i < 10; ++i)// {// as.push_back(i);// }// for ( ast = as.begin(); ast != as.end(); ++ast)// cout << *ast << endl;// // //测试输出结构体// vector<Test> vs;// vector<Test>::iterator t;// Test a, b, c, d;// a.a = 234;// b.a = 452;// c.a = 98;// d.a = 53;// vs.push_back(a);// vs.push_back(b);// vs.push_back(c);// vs.push_back(d);// sort(vs.begin(), vs.end(), SortFunction);// for (t= vs.begin(); t != vs.end();++t)// cout << *t <<endl;// return 0;//}/********************************************************//* 对类成员排序 *//********************************************************///#include <iostream>//#include <algorithm>//#include <functional>//#include <vector>//using namespace std;////class myclass {//public:// myclass(int a, int b) :first(a), second(b){}// int first;// int second;// bool operator < (const myclass &m)const // {// return first < m.first;// }//};////bool less_second(const myclass & m1, const myclass & m2) //{// return m1.second < m2.second;//}////int main() {//// vector< myclass > vect;// for (int i = 0; i < 10; i++)// {// myclass my(10 - i, i * 3);// vect.push_back(my);// }// for (int i = 0; i < vect.size(); i++)// cout << "(" << vect[i].first << "," << vect[i].second << ")\n";// // //以第一个数据升序排序// sort(vect.begin(), vect.end());// cout << "after sorted by first:" << endl;// for (int i = 0; i < vect.size(); i++)// cout << "(" << vect[i].first << "," << vect[i].second << ")\n";// // //以第二个数据降序排序// sort(vect.begin(), vect.end(), less_second);// cout << "after sorted by second:" << endl;// for (int i = 0; i < vect.size(); i++)// cout << "(" << vect[i].first << "," << vect[i].second << ")\n";//// return 0;//}//strcpy#include <assert.h> #include <iostream>using namespace std;char * Strcpy(char* dest, const char* src){ assert(dest != NULL&&src != NULL); char* res = dest; //char aa = *dest++; //指针后移1位 输出为?23abc 第一个位置存放的是随机值,共占用13个位置 while ((*dest++ = *src++) != '\0'); return res;}int main(){ char a[] = "1,2,3,a,b,c"; char d[14]; Strcpy(d, a); cout << d; system("pause"); return 0;}
阅读全文
0 0
- 20170812
- 20170812
- 20170812
- 20170812_eqpt 笔记
- 20170812(交互题)
- MySQL学习笔记——20170812
- 20170812周末记账流水(2017-08-12 10:00)
- 20170812在STM32F103RB上测试RTT硬实时OS
- 20170812_继承与多态测试实例
- 公众号“今日作文素材”文章列表 (20170812-20170818)
- 关于easyui分页时请求两次服务端.md
- 生产者消费者模型
- 关于单片机串口通信波特率问题
- Centos6下SSH免密码连接配置
- Socket
- 20170812
- HDU6108 小C的倍数问题 【脑洞】
- SPOJ
- Java Arrays.sort源代码解析
- GetMemory 改错
- 30分钟全面解析-SQL事务+隔离级别+阻塞+死锁
- Java基础002
- 安卓——问题:控件(view)的OnTouch事件只能获取到ACTION_DOWN事件,UP、MOVE等事件都无法获取到
- 2018网易秋招内推笔试题——独立的小易