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

📄 mp.h

📁 数据结构基础代码
💻 H
字号:
const error=0;
const ok=1;
const ERROR =-1; 
const OVERFLOW =-2; 
const LIST_INIT_SIZE=100; 
const maxsize=200;
const LISTINCREMENT=10;  

//定义线形表的结构
typedef struct {     
        int  *elem;     
        int length;     
        int listsize; 
		int incrementsize;
}sqlist; 
 
//给线形表的元素分配空间
void InitList_Sq(sqlist &l)
{
	l.elem=new int[maxsize];
	l.length=0;
	l.listsize=maxsize;
}
 
//初始化线形表
void create_sq(sqlist &l)
{
	int x;	
	cout<<"请输入线形表的元素:(输入0表示结束!)"<<endl;
	for(int i=1;i<=maxsize;i++)
	{ 
		cin>>x;
		if(x==0)
			break;
		l.elem[i]=x;
		l.length++;
	}
}

//冒泡排序:此时如一个线性表的所有元素是有序的,依然判断一遍
#define swap(a,b)	{int temp;temp=a;a=b;b=temp;}
int bubblesort(sqlist l,int n)
{
	int i,j,count=0;
	for(i=1;i<=n-1;i++)
	{
		for(j=1;j<=n-i;j++)
		{
			if(l.elem[j]>l.elem[j+1])
			{
				swap(l.elem[j],l.elem[j+1]);
				count++;
			}
		}
	}
	return count;
}

//冒泡排序:此时如一趟排序中没有进行过交换元素的操作,就结束排序
int bubblesortch(sqlist l,int n)
{
	int i,j,change,count=0;
	for(i=1,change=1;i<=n-1&&change;i++)
	{
		change=0;
		for(j=1;j<=n-i;j++)
		{
			if(l.elem[j]>l.elem[j+1])
			{
				swap(l.elem[j],l.elem[j+1]);
				count++;
				change=1;
				
			}
		}
	}
	return count;
}

⌨️ 快捷键说明

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