C++
C++学习笔记
不秃头o_o
菜
展开
-
c++判断数字回文(sstream)
定义了三个类:istringstream用来进行流的输入、ostringstream进行流的输出、stringstream进行流的输入输出。主要用来进行数据转换原创 2022-12-29 16:11:03 · 115 阅读 · 0 评论 -
C++ sort函数(升序降序排列)
sort 函数类似于快排,执行效率为n*log2(n),优于冒泡排序和选择排序。#include<iostream>#include<algorithm>//必须包含的头文件using namespace std;int main(){ int arr[10] = { 2,4,1,6,9,10,11,23,45,15}; //升序排列 sort(arr, arr + 10);//参数分别是起始地址,结束地址,排序分式(默认从小到大) for (int i = 0原创 2022-03-14 10:24:24 · 8193 阅读 · 0 评论 -
冒泡排序(c++)
#include<iostream>using namespace std;int main(){ int arr[9] = { 2,4,1,3,5,7,9,6,10 }; cout << "排序前:"; for (int i = 0; i < 9; i++) cout<<arr[i]; cout << endl; //开始冒泡排序 for (int i = 0; i < 9 - 1; i++)//9个数一共排8轮 { .原创 2022-02-11 11:34:09 · 206 阅读 · 0 评论 -
全排列函数 do{}while(next_permutation(a,a+n))
#include<iostream>#include<algorithm>//必须包含的头文件using namespace std;int main(){ int n = 3; int a[3] = { 1,3,7};//数组中的元素按从小到大的顺序 do { for (int i = 0; i <3; i++) cout << a[i] << ' '; cout &l.原创 2022-03-06 15:07:22 · 478 阅读 · 0 评论