ImageVerifierCode 换一换
格式:DOCX , 页数:25 ,大小:55.10KB ,
资源ID:18245610      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/18245610.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(重庆大学操作系统实验Word文档下载推荐.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

重庆大学操作系统实验Word文档下载推荐.docx

1、要实现排序过程,就要有排序算法,有画图工具,有三个线程具体怎么设计?要解释数据结构和函数代码:/* * vim: filetype=c:fenc=utf-8:ts=4:et:sw=4:sts=4 */#include stddef.hmath.hstdio.hsys/mman.hsyscall.hnetinet/in.hstdlib.h#include graphics.htime.hextern void *tlsf_create_with_pool(void* mem, size_t bytes);extern void *g_heap;/* * GCC insists on _main

2、* http:/gcc.gnu.org/onlinedocs/gccint/Collect2.html /进入图形模式 / init_graphic(0x143);void _main() size_t heap_size = 32*1024*1024; void *heap_base = mmap(NULL, heap_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); g_heap = tlsf_create_with_pool(heap_base, heap_size); void swap(int A, int i, in

3、t j) int temp; temp = Ai; Ai = Aj; Aj = temp;/*创建线程 退出线程 获取线程自己的ID 等待线程退出 int task_create(void *tos, void (*func)(void *pv), void *pv);int task_exit(int code_exit);int task_getid();int task_wait(int tid, int *pcode_exit);*/划线函数 void draw1(int y,int x1,int x2) line( x1, y, x2, y,RGB(87,166,163); void

4、 draw2(int y,int x1,int x2) line( x1, y, x2, y,RGB(221,237,252); void draw3(int y,int x1,int x2) line( x1, y, x2, y,RGB(215,171,196); void draw4(int y,int x1,int x2) line( x1, y, x2, y,RGB(184,98,127);/清除划线函数 void clean(int y,int x1,int x2) line( x1, y, x2, y,RGB(0,0,0); int msleep(const uint32_t ms

5、ec) struct timespec ts=0,1000000*msec; return nanosleep(&ts, NULL);/*排序算法*/ Insertion sort implementation 插入排序void inssort(int A, int n,int l) / Insertion Sort int i; int j; int t=5; for (i=0; i0) & (Aji; / Find the least value if (AjAlowindex) lowindex = j; clean(i*t,l,l+Ai); clean(lowindex*t,l,l+A

6、lowindex);/ Put it in place swap(A, i, lowindex); msleep(900); draw2(i*t,l,l+Ai); draw2(lowindex*t,l,l+Alowindex); /冒泡排序void bubsort(int A, int n,int l) / Bubble Sort i+) / Bubble up ith record for ( j=0; jn-1-i; j+) if (Aj+1Aj) clean(j*t,l,l+Aj); clean(j*t+t,l,l+Aj+1); swap(A, j, j+1); msleep(10);

7、draw3(j*t,l,l+Aj); draw3(j*t+t,l,l+Aj+1); /*创建线程函数*/void tsk_inssort(void *pv) printf(This is task inssort with tid=%drn, task_getid(); srand(time(NULL); / int x,y; int i,m; int array100; /进入图形模式 /init_graphic(0x143); /* x=g_graphic_dev.XResolution; y=g_graphic_dev.YResolution; /生成随机数i100;i+) m=rand

8、()%100+1; if(m0) m=0-m; draw4(i*5,0,0+m);/画出随机线条的长度 arrayi=m; inssort(array,100,0); / int exit_graphic();/退出图形模式 task_exit(0);/不能直接return,必须调用task_exitvoid tsk_selsort(void *pv)This is task selsort with tid=%drn int x; x=g_graphic_dev.XResolution; /y=g_graphic_dev.YResolution; draw1(i*5,x/3,x/3+m);

9、selsort(array,100,x/3); /int exit_graphic();void tsk_bubsort(void *pv)This is task bubsort with tid=%drn draw2(i*5,(2*x/3),(2*x/3)+m); bubsort(array,100,(2*x/3); * 第一个运行在用户模式的线程所执行的函数void main(void *pv)task #%d: Im the first user task(pv=0x%08x)!rn, task_getid(), pv); init_graphic(0x143); /TODO: You

10、r code goes here unsigned char *stack_inssort=(unsigned char *)malloc(1024*1024 );/unsigned int stack_size = 1024*1024;unsigned char *stack_selsort = (unsigned char *)malloc(1024*1024 );unsigned char *stack_bubsort= (unsigned char *)malloc(1024*1024 );int tid_inssort,tid_selsort,tid_bubsort;tid_inss

11、ort = task_create(stack_inssort+1024*1024, tsk_inssort, (void *)0);tid_selsort = task_create(stack_selsort+1024*1024, tsk_selsort, (void *)0);tid_bubsort = task_create(stack_bubsort+1024*1024, tsk_bubsort, (void *)0);task_wait(tid_inssort,0);free(stack_inssort);task_wait(tid_selsort, 0);free(stack_s

12、elsort);task_wait(tid_bubsort, 0);free(stack_bubsort);int exit_graphic(); time_t t = 0; t = time(NULL);%ld,t); while(1);最后结果: void draw4(int y,int x1,int x2) void draw5(int x,int y1,int y2) line( x, y1, x, y2,RGB(215,171,196); void draw6(int x,int y1,int y2) line( x, y1, x, y2,RGB(184,98,127); / x=g_graphic_dev.XResolution; /int x; /

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1