⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insertsort.cpp

📁 《数据结构》所有相关程序的算法。有图、数组以及二叉数的问题。附有程序及结果。
💻 CPP
字号:
//InsertSort.cpp
//This function is to sort SqList
# include <iostream.h>
# include <conio.h>

# define MAXSIZE 20
# define MAX_LENGTH 100
typedef int RedType;

typedef struct			//define structure SqList
{   RedType	r[MAXSIZE+1];
    int length;
}SqList;

void InsertSort(SqList &L)	//InsertSort() sub-function
{  int i,j;
   for(i=2;i<=L.length;++i)
       if(L.r[i]<L.r[i-1])
       {  L.r[0]=L.r[i];
	  for(j=i-1;L.r[0]<L.r[j];--j)
	     L.r[j+1]=L.r[j];
	  L.r[j+1]=L.r[0];
       }
}

void main()			//main() function
{  int i;
   SqList L;
   cout<<endl<<endl<<"InsertSort.cpp";
   cout<<endl<<"==============";
   cout<<endl<<"Please input the length of SqList (eg,5): "<<endl<<endl;
   cin>>L.length;
   for(i=1;i<=L.length;++i)
   {   cout<<"Please input the "<<i<<"th integer (eg,58): ";
       cin>>L.r[i];
   }
   cout<<endl<<"The disordered : ";
   for(i=1;i<=L.length;i++)
       cout<<L.r[i]<<"  ";
   InsertSort(L);		//call InsertSort()
   cout<<endl<<"The ordered    : ";
   for(i=1;i<=L.length;i++)
     cout<<L.r[i]<<"  ";
   cout<<endl<<endl<<"...OK!...";
   getch();
} //main() end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -