《算法导论》–排序算法@[TOC]算法入门(这里写自定义目录标题)

  1. 插入排序

算法导论

//插入排序
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int num[100];
void insert_sort(int a[],int n)
{
 for(int j=1;j<n;j++)//insert a[j]into the sorted sequence
 {
  int key=a[j];
  int i=j-1;
  while(i>=0&a[i]>key)
  {
   a[i+1]=a[i];
   i--;
  }
  a[i+1]=key;
 }
 } 
int main()
{
 ifstream infile;int i;
 infile.open("num100.txt");
 for(i=0;i<100;i++)
 {
  infile>>num[i];
 }
 insert_sort(num,100);
 infile.close();
 ofstream outfile;
 outfile.open("out.txt");
 for(i=0;i<100;i++)
 {
  outfile<<num[i]<<" ";
 }
 outfile.close();
 return 0;
 } 

rl/Command + Z
重做:Ctrl/Command + Y
加粗:Ctrl/Command + B
斜体:Ctrl/Command + I
标题:Ctrl/Command + Shift + H
无序列表:Ctrl/Command + Shift + U
有序列表:Ctrl/Command + Shift + O
检查列表:Ctrl/Command + Shift + C
插入代码:Ctrl/Command + Shift + K
插入链接:Ctrl/Command + Shift + L
插入图片:Ctrl/Command + Shift + G

相关文章:

  • 2021-10-16
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-20
  • 2022-12-23
  • 2021-07-18
  • 2021-11-23
  • 2021-09-12
相关资源
相似解决方案