摘要: 已知A,B和C为三个递增有序的线性表,现要求对A表作如下操作:删去那些既在B表中出现又在C表中出现的元素。试对顺序表编写实现上述操作的算法.(注意:题中没有特别指明同一表中的元素值各不相同)。C code:#include<stdio.h>#include<stdlib.h>#defineLIST_INIT_SIZE10#defineLIST_INCREMENT2#defineERROR0#defineOK1#defineOVERFLOW-1#defineTRUE1typedefintStatus;structSqList{int*elem;intlength;intl 阅读全文
posted @ 2011-05-03 23:46 cpoint 阅读(720) 评论(0) 推荐(2) 编辑
摘要: 假设以两个元素依值递增有序排列的线性表A和B分别表示两个集合(即同一表中的元素值各不相同),现要求另辟空间构成一个线性表C,其元素为A和B中元素的交集,且表C中的元素有依值递增有序排列。试对顺序表编写求C的算法。C code:#include<stdio.h>#include<stdlib.h>#defineLIST_INIT_SIZE10#defineLIST_INCREMENT2#defineERROR0#defineOK1#defineOVERFLOW-1#defineTRUE1typedefintStatus;structSqList{int*elem;intl 阅读全文
posted @ 2011-04-28 23:48 cpoint 阅读(1023) 评论(0) 推荐(1) 编辑
摘要: 设线性表A=(a1,a2……,am),B=(b1,b2……,bn),试写一个按下列规则合并A,B为线性表C的算法,即使得C=(a1,b1,……am,bm,……bn) 当m<=n时;C=(a1,b1,……an,bn,……am) 当m>n时;C code:#include<stdio.h>#include<stdlib.h>#defineLIST_INIT_SIZE10#defineLIST_INCREMENT2#defineERROR0#defineOK1#defineOVERFLOW-1#defineTRUE1typedefintStatus;structS 阅读全文
posted @ 2011-04-28 01:42 cpoint 阅读(566) 评论(0) 推荐(0) 编辑
摘要: 已知指针ha和hb分别指向两个单链表的头结点,并且已知两个链表的长度分别为m和n。试写一算法将这两个链表连接在一起,假设指针hc指向连接后的链表的头结点,并要求算法以尽可能短的时间完成连接运算。C code:#include<stdio.h>#include<stdlib.h>#defineLIST_INIT_SIZE10#defineLIST_INCREMENT2#defineERROR0#defineOK1#defineOVERFLOW-1#defineTRUE1typedefintStatus;structLNode{intdata;LNode*next;};ty 阅读全文
posted @ 2011-04-27 23:37 cpoint 阅读(373) 评论(0) 推荐(0) 编辑
摘要: 1、试写一算法在带头结点的单链表结构上实现线性表操作Locate(L,x)2、试写一算法在带头结点的单链表结构上实现线性表操作Length(L)C code:#include<stdio.h>#include<stdlib.h>#defineERROR0#defineOK1#defineOVERFLOW-1#defineTRUE1typedefintStatus;structLNode{intdata;LNode*next;};typedefLNode*LinkList;voidInitList(LinkList&L){L=(LinkList)malloc(si 阅读全文
posted @ 2011-04-27 20:59 cpoint 阅读(532) 评论(0) 推荐(0) 编辑
摘要: 设顺序表va中的数据元素递增有序。试写一算法,将x插入到顺序表的适当位置上,以保持该表的有序性。算法:StatusInsert_Sqlist(SqList&va,intx){inti;if(va.length+1>va.listsize)returnERROR;va.length++;for(i=va.length-1;va.elem[i]>x&&i>=0;i--)va.elem[i+1]=va.elem[i];va.elem[i+1]=x;returnOK;}C code:#include<stdio.h>#include<stdl 阅读全文
posted @ 2011-04-27 17:57 cpoint 阅读(513) 评论(0) 推荐(1) 编辑
摘要: 七种qsort排序方法<本文中排序都是采用的从小到大排序>一、对int类型数组排序int num[100];Sample:int cmp ( const void *a , const void *b ){return *(int *)a - *(int *)b;}qsort(num,100,sizeof(num[0]),cmp);二、对char类型数组排序(同int类型)char word[100];Sample:int cmp( const void *a , const void *b ){return *(char *)a - *(int *)b;}qsort(word,1 阅读全文
posted @ 2011-04-27 16:50 cpoint 阅读(300) 评论(0) 推荐(1) 编辑
摘要: #include<stdio.h>#include<stdlib.h>typedefstructnode*link;structnode{intitem;linknext;};intmain(){inti,N,M;scanf("%d%d",&N,&M);linkt=malloc(sizeof*t),x=t;t->item=1;t->next=t;for(i=2;i<=N;i++){x=(x->next=malloc(sizeof*x));x->item=i;x->next=t;}while(x!=x 阅读全文
posted @ 2011-04-26 15:46 cpoint 阅读(266) 评论(0) 推荐(0) 编辑
摘要: 如果抛掷硬币N次,看到头像的期望值是N/2次,但实际值也可能是0~N次,以下程序进行M次试验,M和N都从命令行获取。它使用一个数组f来跟踪出现“i次头像”的概率,其中0<=i<=N。然后打印试验结果的柱状图。#include<stdlib.h>#include<stdio.h>intheads(){returnrand()<RAND_MAX/2;}main(intargc,char*argv[]){inti,j,cnt;intN=atoi(argv[1]),M=atoi(argv[2]);int*f=malloc((N+1)*sizeof(int)); 阅读全文
posted @ 2011-04-25 23:08 cpoint 阅读(318) 评论(0) 推荐(1) 编辑
摘要: 若i为素数,则设置a[i]为1;反之则设置为0.首先,将所有数组的元素设置为1,表示没有已知的非素数。然后将已知为非素数(即为已知素数的倍数)的索引对应的数组元素设置为0。如果将所有较小的素数的倍数都设置为0之后,a[i]仍然保持为1,则可判断它是所找的素数。#include<stdio.h>#defineN10000intmain(){inti,j,a[N];for(i=2;i<N;i++)a[i]=1;for(i=2;i<N;i++)if(a[i])for(j=i;j<N/i;j++)a[i*j]=0;for(i=2;i<N;i++)if(a[i])pr 阅读全文
posted @ 2011-04-25 22:54 cpoint 阅读(635) 评论(0) 推荐(0) 编辑
浏览次数:travelocity promotion codes