首页 > 其他 > 详细

每周总结

时间:2020-06-11 20:40:56      阅读:32      评论:0      收藏:0      [点我收藏+]

这一周复习了数据结构与算法的顺序表和链表,了解了顺序表和链表的区别

以下是一些总结和代码:

    CreatList(SqList &L,int n) 参数:顺序表L,顺序表长度n 功能:创建长度为的顺序表 时间复杂度:O(n)
    InitList(SqList &L) 参数:顺序表L 功能:初始化
    InsertList(SqList &L,int i,ElemType e) 参数:顺序表L,位置i,元素e 功能:位置i处插入元素e
    ListDelete(SqList &L,int i) 参数:顺序表L,位置i 功能:删除位置i处元素
    LocateElem(SqList L,ElemType e) 参数:顺序表L,元素e 功能:返回第一个等于e的元素的位置
    PrintList(SqList L) 参数:顺序表L 功能:遍历L,并输出
  SplitSort(SqList &L) 参数:顺序表L 功能:分开奇偶,并分开排序

#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;
#define range 10000
void myrandom(int a[],int len)
{
	srand((unsigned)  time(NULL));
	for(int i=0;i<len;i++)
	a[i]=rand()%range+1;
}
void InsertionSort(int a[],int len)
{
	int k,current;
	for(int i=1;i<len;i++)
	{
		k=a[i];
		current=i-1;
		for(;current>=0&&a[current]>k;current--)
		{
			a[current+1]=a[current];
		}
		a[current+1]=k;
	}
}
int main()
{
	clock_t start,end;
	start=clock();
	freopen("out.txt","r",stdin);
	freopen("out插入排序.txt","w",stdout);
	int arr[range];
	int n=range;
	myrandom(arr,n);
	InsertionSort(arr,n);
	for(int i=0;i<n;i++)
	{
		printf("%5d ",arr[i]);
	}
	cout<<endl;
	end=clock();
	cout<<"插入排序共计用时:"<<(float)(end-start)*1000.0/CLOCKS_PER_SEC<<"ms"<<endl; 
	return 0;
}

 

每周总结

原文:https://www.cnblogs.com/jiangyiying/p/13095583.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!