求各位高手帮忙,用c#或c++写一个200行左右的程序,要有注释,能让人...

求各位高手帮忙,用c#或c++写一个200行左右的程序,要有注释,能让人看懂,谢了!

题目:
设有两个用单链表表示的集合A、B,其元素类型是int且以非递减方式存储,其头结点分别为a、b。要求下面各问题中的结果集合同样以非递减方式存储,结果集合不影响原集合。
实现要求:
⑴ 编写集合元素测试函数IN_SET,如果元素已经在集合中返回0,否则返回1;
⑵ 编写集合元素输入并插入到单链表中的函数INSERT_SET,保证所输入的集合中的元素是唯一且以非递减方式存储在单链表中;
⑶ 编写集合元素输出函数,对建立的集合链表按非递增方式输出;
⑷ 编写求集合A、B的交C=A∩B的函数,并输出集合C的元素;
⑸ 编写求集合A、B的并D=A∪B的函数,并输出集合D的元素;

实现: VC6.0(C实现 控制台)
// SET.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

/*

*2012年4月10日21:17:33

*功能:集合

*说明:默认第一个节点[下标为0],作为垃圾回收头节点,所以任何指向第一个节点[下标为0],都认为指向结束

*我就不认真写算法了,具体要改进的话,你在我的这个框架下很容易改的

*/

#define ARG_SETADT_SIZE 255

//函数声明

//初始化

boolSetNew(struct arg_SetADT*constpthis);

//测试函数

boolSetIN_SET(struct arg_SetADT*constpthis, int m_data);

//输入并插入到单链表中的函数

boolSetINSERT_SET(struct arg_SetADT*constpthis, int m_data);

//集合元素输出函数

voidSetPrint(struct arg_SetADT*constpthis);

//获取第一个数据

boolSetGetFirstData(struct arg_SetADT*constpthis, int *const pm_data);

//获取下一个数据

boolSetGetNextData(struct arg_SetADT*constpthis, int *const pm_data);

//集合A、B的交C=A∩B的函数

boolSetMixed(struct arg_SetADT*constpthis, struct arg_SetADT*constpA, struct arg_SetADT*constpB);

//集合A、B的并D=A∪B的函数

boolSetAnd(struct arg_SetADT*constpthis, struct arg_SetADT*constpA, struct arg_SetADT*constpB);

//销毁

voidSetDestroy(struct arg_SetADT*constpthis);

//节点

typedef struct arg_SetParADT

{

intm_index;//索引

intm_data;//数据

intm_point;//指针

}arg_SetParCDT, *parg_SetParCDT;

//集合对象

typedef struct arg_SetADT

{

//数据

//数据链

arg_SetParCDTsz_List[ARG_SETADT_SIZE];

//头节点索引

intm_Index;

//数据个数

intm_Length;

//处理函数

//初始化

bool(*New)(struct arg_SetADT*constpthis);

//测试函数

bool(*IN_SET)(struct arg_SetADT*constpthis, int m_data);

//输入并插入到单链表中的函数

bool(*INSERT_SET)(struct arg_SetADT*constpthis, int m_data);

//集合元素输出函数

void(*Print)(struct arg_SetADT*constpthis);

//获取第一个数据

bool(*GetFirstData)(struct arg_SetADT*constpthis, int *const pm_data);

//获取下一个数据

bool(*GetNextData)(struct arg_SetADT*constpthis, int *const pm_data);

//集合A、B的交C=A∩B的函数

bool(*Mixed)(struct arg_SetADT*constpthis, struct arg_SetADT*constpA, struct arg_SetADT*constpB);

//集合A、B的并D=A∪B的函数

bool(*And)(struct arg_SetADT*constpthis, struct arg_SetADT*constpA, struct arg_SetADT*constpB);

//销毁

void(*Destroy)(struct arg_SetADT*constpthis);

}arg_SetCDT, *parg_SetCDT;

//初始化

boolSetNew(constparg_SetCDTpthis)

{

//断言有初始化

assert(NULL != pthis->New);

int m_temp = 0;

//数据初始化

pthis->m_Length = 0;

pthis->m_Index= 0;

//

pthis->sz_List[0].m_index = -1;

//建立垃圾回收机制

pthis->sz_List[0].m_point = 1;

for (m_temp = 1; m_temp < ARG_SETADT_SIZE; m_temp++)

{

//垃圾池中可用节点个数

pthis->sz_List[0].m_data++;

pthis->sz_List[m_temp].m_index = m_temp;

//指针指向下一个节点

pthis->sz_List[m_temp].m_point = m_temp + 1;

}

//没有节点指向

pthis->sz_List[m_temp].m_point = 0;

//函数绑定

pthis->New= SetNew;

pthis->IN_SET= SetIN_SET;

pthis->INSERT_SET= SetINSERT_SET;

pthis->Print= SetPrint;

pthis->GetFirstData= SetGetFirstData;

pthis->GetNextData= SetGetNextData;

pthis->Mixed= SetMixed;

pthis->And= SetAnd;

pthis->Destroy= SetDestroy;

return true;

}

//测试函数

boolSetIN_SET(struct arg_SetADT*constpthis, int m_data)

{

int m_temp = 0;

int m_point = 0;

//没有数据

if (pthis->m_Length == 0)

{

return false;

}

m_point = pthis->m_Index;

for (m_temp = 0; m_temp < pthis->m_Length; m_temp++)

{

if (m_data == pthis->sz_List[m_point].m_data)

{

return true;

}

m_point = pthis->sz_List[m_point].m_point;

}

assert(0 == m_point);

return false;

}

//输入并插入到单链表中的函数

boolSetINSERT_SET(constparg_SetCDTpthis, int m_data)

{

intm_point = 0;

//查看垃圾池中是否还有节点

if (0 == pthis->sz_List[0].m_data)

{

return false;

}

//保持数据唯一

if (pthis->IN_SET(pthis, m_data))

{

return false;

}

//从垃圾池中获取节点

m_point = pthis->sz_List[0].m_point;

pthis->sz_List[0].m_point = pthis->sz_List[m_point].m_point;

pthis->sz_List[0].m_data--;

//校验数据

assert(m_point);

//数据赋值 插入数据

pthis->sz_List[m_point].m_data = m_data;

pthis->sz_List[m_point].m_point = pthis->m_Index;

pthis->m_Index = m_point;

pthis->m_Length++;

return true;

}

//集合元素输出函数

voidSetPrint(constparg_SetCDTpthis)

{

int m_temp = 0;

int m_point = pthis->m_Index;

for (m_temp = 0; m_temp < pthis->m_Length; m_temp++)

{

printf("第%d个数据:%d\n",m_temp+1, pthis->sz_List[m_point].m_data);

m_point = pthis->sz_List[m_point].m_point;

//assert(m_point);

}

}

//获取第一个数据

boolSetGetFirstData(struct arg_SetADT*constpthis, int *const pm_data)

{

if (0 == pthis->m_Length)

{

return false;

}

*pm_data = pthis->sz_List[pthis->m_Index].m_data;

//第一个[下标为0]的索引号作为数据移动的记录点

pthis->sz_List[0].m_index = pthis->sz_List[pthis->m_Index].m_point;

return true;

}

//获取下一个数据

boolSetGetNextData(struct arg_SetADT*constpthis, int *const pm_data)

{

if (-1 == pthis->sz_List[0].m_index)

{

return pthis->GetFirstData(pthis, pm_data);

}

if (0 == pthis->sz_List[0].m_index)

{

return false;

}

*pm_data = pthis->sz_List[pthis->sz_List[0].m_index].m_data;

//第一个[下标为0]的索引号作为数据移动的记录点

pthis->sz_List[0].m_index = pthis->sz_List[pthis->sz_List[0].m_index].m_point;

return true;

}

//集合A、B的交C=A∩B的函数

boolSetMixed(struct arg_SetADT*constpthis, struct arg_SetADT*constpA, struct arg_SetADT*constpB)

{

int m_data = 0;

int m_temp = 0;

//如果C中本身有数据

if (0 != pthis->m_Length)

{

return false;

}

//A B都有

if( pA->GetFirstData(pA, &m_data) ){

//检测数据是否在B

if (pB->IN_SET(pB, m_data))

{

pthis->INSERT_SET(pthis, m_data);

}

}else{

return false;

}

for (m_temp = 1; m_temp < pA->m_Length; m_temp++)

{

if( pA->GetNextData(pA, &m_data) ){

//检测数据是否在B

if (pB->IN_SET(pB, m_data))

{

pthis->INSERT_SET(pthis, m_data);

}

}else{

return true;

}

}

return true;

}

//集合A、B的并D=A∪B的函数

boolSetAnd(struct arg_SetADT*constpthis, struct arg_SetADT*constpA, struct arg_SetADT*constpB)

{

int m_data = 0;

int m_temp = 0;

//取A值

if( pA->GetFirstData(pA, &m_data) ){

pthis->INSERT_SET(pthis, m_data);

}

for (m_temp = 0; m_temp < pA->m_Length; m_temp++)

{

if( pA->GetNextData(pA, &m_data) ){

pthis->INSERT_SET(pthis, m_data);

}

}

//取B值

if( pB->GetFirstData(pB, &m_data) ){

pthis->INSERT_SET(pthis, m_data);

}

for (m_temp = 0; m_temp < pB->m_Length; m_temp++)

{

if( pB->GetNextData(pB, &m_data) ){

pthis->INSERT_SET(pthis, m_data);

}

}

return true;

}

//销毁

voidSetDestroy(constparg_SetCDTpthis)

{

//因为没有申请内存,所以直接清除数据即可

pthis->m_Length = 0;

memset(pthis->sz_List, 0, sizeof(arg_SetParCDT)*ARG_SETADT_SIZE);

//解除函数绑定

pthis->New= NULL;

pthis->IN_SET= NULL;

pthis->INSERT_SET= NULL;

pthis->Print= NULL;

pthis->GetFirstData= NULL;

pthis->GetNextData= NULL;

pthis->Mixed= NULL;

pthis->And= NULL;

pthis->Destroy= NULL;

}

int main(int argc, char* argv[])

{

arg_SetCDT A;

arg_SetCDT B;

arg_SetCDT C;

arg_SetCDT D;

A.New = SetNew;

A.New(&A);

B.New = SetNew;

B.New(&B);

C.New = SetNew;

C.New(&C);

D.New = SetNew;

D.New(&D);

A.INSERT_SET(&A, 40);

A.INSERT_SET(&A, 10);

A.INSERT_SET(&A, 55);

A.INSERT_SET(&A, 45);

A.INSERT_SET(&A, 52);

A.INSERT_SET(&A, 51);

A.INSERT_SET(&A, 35);

A.INSERT_SET(&A, 39);

A.INSERT_SET(&A, 39);

printf("\nA\n");

A.Print(&A);

B.INSERT_SET(&B, 32);

B.INSERT_SET(&B, 12);

B.INSERT_SET(&B, 61);

B.INSERT_SET(&B, 45);

B.INSERT_SET(&B, 31);

B.INSERT_SET(&B, 36);

B.INSERT_SET(&B, 24);

printf("\nB\n");

B.Print(&B);

printf("\n AND \n");

C.And(&C, &A, &B);

C.Print(&C);

printf("\n MIXED \n");

D.Mixed(&D, &A, &B);

D.Print(&D);

A.Destroy(&A);

B.Destroy(&B);

C.Destroy(&C);

D.Destroy(&D);

return 0;

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-13
很多:

#include"dos.h"
#include"math.h"
#include"time.h"
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
int i,j,fx,fy,t,p,q,s,z;
int x[8][4]={ 0,0,0,0,
0,-2,-1,0,
0,0,1,2,
0,0,0,0,
0,-1,0,1,
0,0,1,1,
0,-1,0,1,
0,-1,0,1
};
int y[8][4]={ 0,0,0,0,
0,0,0,1,
0,1,0,0,
0,1,2,3,
0,0,1,0,
0,1,0,1,
0,1,1,0,
0,0,1,1
};
int m[25]={0};
display(int i,int t)
{
for(j=0;j<4;j++)
{
textcolor(i);
p=fx+x[i][j];
q=fy+y[i][j];
gotoxy(p,q); putch(t);
}
}

test()
{
char tmp[2];
s=0;
for(j=0;j<4;j++)
{
q=fy+y[i][j]; p=fx+x[i][j];
gettext(p,q,p,q,&tmp);
if(tmp[0]!=32) s=1;
}
}

turn()
{
for(j=1;j<=3;j++)
{
z=x[i][j]; x[i][j]=-y[i][j]; y[i][j]=z;
}
test();
if(s==1)
{
for(j=1;j<=3;j++)
{
z=y[i][j]; y[i][j]=x[i][j]; x[i][j]=z;
}
}
}

left()
{
int ox;
t=32; display(i,t);
ox=fx; fx--;
test();
if(s==1) fx=ox;
t=219; display(i,t);
}

right()
{
int ox;
t=32; display(i,t);
ox=fx; fx++;
test();
if(s==1) fx=ox;
t=219; display(i,t);
}

inkey()
{
int k;
if(kbhit())
{
k=getch();
if(k==27) exit(0);
if(k==0)
{
k=getch();
switch(k)
{
case 77: right(); delay(50); break;
case 75: left(); delay(50); break;
case 72: turn(); delay(50); break;
break;
}
}
}
}

full()
{
int fj=0;
char tmp[2];
for(j=0;j<=3;j++)
{
fj=fy+y[i][j];
m[fj]=0;
for(p=11;p<=26;p++)
{
gettext(p,fj,p,fj,&tmp);
if(tmp[0]!=32) m[fj]=m[fj]+1;
}
}
}

int main()
{
int z,mabo;
union REGS r;
textmode(C40);
system("cls");
r.x.ax=0x0100;
r.x.cx=0x2000;
int86(0x10,&r,&r);
randomize();
for(i=4;i<=23;i++)
{
gotoxy(10,i); putch(178);
gotoxy(27,i); putch(178);
}
for(i=10;i<=27;i++)
{
gotoxy(i,24); putch(178);
}
gone: i=rand()%7+1; fy=3;fx=18;
while(1)
{
inkey();
display(i,2); delay(32000); delay(32000); delay(18000);
display(i,32);
fy++;
test();
if(s==1)
{
fy--; display(i,2); full();
for(z=23;z>=4;z--)
{
gotoxy(30,z); printf("%d",m[z]);
}
goto gone;
}
}
getch();
}

2.
#include"dos.h"
#include"math.h"
#include"time.h"
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
int i,j,fx,fy,t,p,q,s,z;
int x[8][4]={ 0,0,0,0,
0,-2,-1,0,
0,0,1,2,
0,0,0,0,
0,-1,0,1,
0,0,1,1,
0,-1,0,1,
0,-1,0,1
};
int y[8][4]={ 0,0,0,0,
0,0,0,1,
0,1,0,0,
0,1,2,3,
0,0,1,0,
0,1,0,1,
0,1,1,0,
0,0,1,1
};
int m[25]={0};
display(int i,int t)
{
for(j=0;j<4;j++)
{
textcolor(i);
p=fx+x[i][j];
q=fy+y[i][j];
gotoxy(p,q); putch(t);
}
}

test()
{
char tmp[2];
s=0;
for(j=0;j<4;j++)
{
q=fy+y[i][j]; p=fx+x[i][j];
gettext(p,q,p,q,&tmp);
if(tmp[0]!=32) s=1;
}
}

turn()
{
for(j=1;j<=3;j++)
{
z=x[i][j]; x[i][j]=-y[i][j]; y[i][j]=z;
}
test();
if(s==1)
{
for(j=1;j<=3;j++)
{
z=y[i][j]; y[i][j]=x[i][j]; x[i][j]=z;
}
}
}

left()
{
int ox;
t=32; display(i,t);
ox=fx; fx--;
test();
if(s==1) fx=ox;
t=219; display(i,t);
}

right()
{
int ox;
t=32; display(i,t);
ox=fx; fx++;
test();
if(s==1) fx=ox;
t=219; display(i,t);
}

inkey()
{
int k;
if(kbhit())
{
k=getch();
if(k==27) exit(0);
if(k==0)
{
k=getch();
switch(k)
{
case 77: right(); delay(50); break;
case 75: left(); delay(50); break;
case 72: turn(); delay(50); break;
break;
}
}
}
}

full()
{
int fj=0;
char tmp[2];
for(j=0;j<=3;j++)
{
fj=fy+y[i][j];
m[fj]=0;
for(p=11;p<=26;p++)
{
gettext(p,fj,p,fj,&tmp);
if(tmp[0]!=32) m[fj]=m[fj]+1;
}
}
}

int main()
{
int z,mabo;
union REGS r;
textmode(C40);
system("cls");
r.x.ax=0x0100;
r.x.cx=0x2000;
int86(0x10,&r,&r);
randomize();
for(i=4;i<=23;i++)
{
gotoxy(10,i); putch(178);
gotoxy(27,i); putch(178);
}
for(i=10;i<=27;i++)
{
gotoxy(i,24); putch(178);
}
gone: i=rand()%7+1; fy=3;fx=18;
while(1)
{
inkey();
display(i,2); delay(32000); delay(32000);
display(i,32);
fy++;
test();
if(s==1)
{
fy--; display(i,2); full();
for(z=23;z>=4;z--)
{
gotoxy(30,z); printf("%d",m[z]);
}
goto gone;
}
}
getch();
}
(省略号)
第2个回答  2012-04-12
int main()
{
//打印
printf("Hello 1");
printf("Hello 2");
printf("Hello 3");
printf("Hello 4");
printf("Hello 5");
printf("Hello 6");
printf("Hello 7");
...
printf("Hello 198");
printf("Hello 199");
printf("Hello 200");
return 0;
}追问

麻烦敬业点

第3个回答  2012-04-15
…………有要求吗?
相似回答