File tree Expand file tree Collapse file tree 1 file changed +43
-4
lines changed
Expand file tree Collapse file tree 1 file changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -114,10 +114,49 @@ <h1>挑战20学会5种算法</h1>
114114 < div class ="code-title "> 插入排序+函数</ div >
115115 < button class ="copy-btn " onclick ="copyCode() "> 复制代码</ button >
116116 </ div >
117- < pre id ="code-content "> // 这里放置您的代码
118- function example() {
119- console.log("这是示例代码");
120- return "Hello World!";
117+ < pre id ="code-content "> #include < iostream >
118+ using namespace std;
119+
120+ const int maxx = 1001;
121+ int a[maxx];
122+
123+ void sort(int a[], int n)
124+ {
125+ //排序
126+ for(int i = 2; i < = n; i++)
127+ {
128+ int key = a[i];
129+ int j = i -1;
130+ while(j > = 1 && a[j] > key)
131+ {
132+ //交换位置
133+ a[j+1] = a[j];
134+ j--;
135+ }
136+ a[j+1]=key;
137+ }
138+ }
139+
140+ int main()
141+ {
142+ int n;
143+ cout< < "输入数个数:";
144+ cin > > n;
145+ for(int i = 1; i < = n; ++i)
146+ {
147+ //输入部分
148+ cout< < "输入:";
149+ cin > > a[i];
150+ }
151+ sort(a,n);//调用函数
152+ for(int i = 1; i < = n; ++i)
153+ {
154+ //输出部分
155+ cout < < a [i];
156+ cout < < " ";
157+ }
158+
159+ }
121160}</ pre >
122161 </ div >
123162 </ div >
You can’t perform that action at this time.
0 commit comments