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

📄 insertio.cpp

📁 数据结构课程程序
💻 CPP
字号:
/******Don't forget to download*****
*****GRAPHICAL DATA FILE STRUCTURE*****
*****A approach to learn DFS Graphically*****
Only @  http://www.vivekpatel.cjb.net        */

//Insertion Sort


//Programmed by : Vivek Patel
//URL : www.vivekpatel.cjb.net
//Email : vivek_patel9@rediffmail.com


#include <iostream.h>
#include <conio.h>
#define MAX 10

class Inssort{
	int arr[MAX],n;
	public:
	void getdata();
	void showdata();
	void sortLogic();
};

void Inssort :: getdata(){
	cout<<"How many elements you require : ";
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>arr[i];
}

void Inssort :: showdata(){
	cout<<"\n--Display--\n";
	for(int i=0;i<n;i++)
		cout<<arr[i]<<"   ";
}

void Inssort :: sortLogic(){
	int temp,min;
	for(int i=1;i<n;i++){
		temp = arr[i];
		for(int j=i;j>0 && arr[j-1]>temp;j--){
			arr[j] = arr[j-1];
		}
		arr[j] = temp;
	}
}

void main(){
	clrscr();
	cout<<"\n*****Insertion Sort*****\n";
	Inssort obj;
	obj.getdata();
	obj.sortLogic();
	obj.showdata();
	getch();
}

⌨️ 快捷键说明

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