急!程序分析爱好者,请帮我分析一下!!!急,急,急!!
1.
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#define ERROR 0
#define OK 1
#define EQUAL 1
#define OVERFLOW -1
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
struct STU{
char name[20];
char stuno[10];
int age;
int score;
}stu[50];
typedef struct STU ElemType;
struct LNODE
{
ElemType data;
struct LNODE *next;
};
typedef struct LNODE LNode;
typedef struct LNODE *LinkList;
int init(LinkList *L)
{
*L=(LNode *)malloc(sizeof(LNode));
if(!L) exit(ERROR);
(*L)->next=NULL;
return OK;
}/*init */
int ListLength(LinkList L)
{
int j=0;
while (L->next)
{
L=L->next;
j++;
}
return j;
}
int GetElem(LinkList L,int i,ElemType *e)
{
LinkList p; int j;
p=L->next;j=1;
while(p&&j<i){
p=p->next;++j;
}
if(!p||j>1) return ERROR;
*e=p->data;
return OK;
}
int EqualList(ElemType *e1,ElemType *e2)
{
if (strcmp(e1->name,e2->name)==0)
return 1;
else
return 0;
}
int Less_EqualList(ElemType *e1,ElemType *e2)
{
if (strcmp(e1->name,e2->name)<=0)
return 1;
else
return 0;
}
int LocateElem(LinkList La,ElemType e,int type)
{
int i;
LinkList p;
p=La;
switch (type)
{
case EQUAL:
while(p->next)
{
p=p->next;
if(EqualList(&p->data,&e))
return 1;
}
return 0;
break;
default:
break;
}
return 0;
}
void MergeList(LinkList La,LinkList Lb,LinkList *Lc)
{
LinkList pa,pb,pc;
pa=La->next;pb=Lb->next;
*Lc=pc=La;
while(pa && pb)
{
if(Less_EqualList(&pa->data,&pb->data))
{
pc->next=pa;pc=pa;pa=pa->next;
}
else
{
pc->next=pb;pc=pb;pb=pb->next;
}
}
pc->next=pa?pa:pb;
free(Lb);
}
int printlist(LinkList L)
{
int i;
LinkList p;
p=L;
printf("name stuno age score\n");
while(p->next)
{
p=p->next;
printf("%-10s %s\t%d\t%d\n", p->data.name, p->data.stuno,
p->data.age, p->data.score);
}
printf("\n");
}
int ListInsert(LinkList L,int i,ElemType e)
{
LinkList p,s;
int j;
p=L;j=0;
while(p&&j<i-1)
{
p=p->next;
++j;
}
if(!p||j>i-1) return ERROR;
s=(LinkList)malloc(sizeof(LNode));
s->data=e;
s->next=p->next;
p->next=s;
return OK;
}/*ListInsert Before i */
main()
{
struct STU e;
LinkList La,Lb,Lc;
clrscr();
printf("\n\n-------------------List Demo is running...----------------\n\n");
printf("First is InsertList function.\n");
init(&La);
strcpy(e.name,"stu1");
strcpy(e.stuno,"100001");
e.age=80;
e.score=1000;
ListInsert(La,1,e);
strcpy(e.name,"stu3");
strcpy(e.stuno,"100002");
e.age=80;
e.score=1000;
ListInsert(La,2,e);
printlist(La);
getch();
strcpy(e.name,"stu5");
strcpy(e.stuno,"100003");
e.age=80;
e.score=1000;
ListInsert(La,3,e);
printlist(La);
getch();
init(&Lb);
strcpy(e.name,"stu2");
strcpy(e.stuno,"100001");
e.age=80;
e.score=1000;
ListInsert(Lb,1,e);
strcpy(e.name,"stu4");
strcpy(e.stuno,"100002");
e.age=80;
e.score=1000;
ListInsert(Lb,2,e);
strcpy(e.name,"stu6");
strcpy(e.stuno,"100001");
e.age=80;
e.score=1000;
ListInsert(Lb,3,e);
printlist(Lb);
getch();
MergeList(La,Lb,&Lc);
printlist(Lc);
getch();
printf("\n\n\n\n\n\nWelcome to visit http://zmofun.heha.net !\n\n\n\n\n\n\n");
}
2.
#include<stdio.h>
#include<string.h>
#define ERROR 0
#define OK 1
struct STU{
char name[20];
char stuno[10];
int age;
int score;
}stu[50];
struct LIST
{
struct STU stu[50];
int length;
}L;
int printlist(struct LIST L)
{
int i;
printf("name stuno age score\n");
for(i=0;i<L.length;i++)
printf("%s %s\t%d\t%d\n", L.stu[i].name, L.stu[i].stuno,
L.stu[i].age, L.stu[i].score);
printf("\n");
return 0;
}
int listinsert(struct LIST *L,int i,struct STU e)
{
struct STU *p,*q;
if (i<1||i>L->length+1) return ERROR;
q=&(L->stu[i-1]);
for(p=&L->stu[L->length-1];p>=q;--p)
*(p+1)=*p;
*q=e;
++L->length;
return OK;
}/*ListInsert Before i */
main()
{
struct STU e;
L.length=0;
strcpy(e.name,"zmofun");
strcpy(e.stuno,"100001");
e.age=80;
e.score=1000;
listinsert(&L,1,e);
printlist(L);
printf("List length now is %d.\n\n",L.length);
strcpy(e.name,"bobjin");
strcpy(e.stuno,"100002");
e.age=80;
e.score=1000;
listinsert(&L,1,e);
printlist(L);
printf("List length now is %d.\n\n",L.length);
}
问题点数:80、回复次数:8Top
1 楼ykzhujiang(朱朱)回复于 2006-03-15 16:24:14 得分 20
最好把你遇到的问题以及你想实现的功能详细说一下Top
2 楼pyrophile(豆子(天上云彩往下飘))回复于 2006-03-15 17:12:35 得分 20
说一下你的意思Top
3 楼jiangjundu(将军肚卸顶没文化穷)回复于 2006-03-15 17:23:11 得分 20
LZ你到底想问什么呀?是看不懂这个程序的意思呢还是需要改错?
需要说清楚Top
4 楼citywanderer2005(流浪狗)回复于 2006-03-15 18:05:38 得分 0
眼花了Top
5 楼minsavage(帆野)回复于 2006-03-15 18:12:06 得分 0
呵呵 看起来很眼熟Top
6 楼huangyi_234()回复于 2006-03-15 21:01:30 得分 0
我是想知道源代码程序中每行语句的功能是什么?
还有他最后又什么功能?
就这样而已
Top
7 楼huangyi_234()回复于 2006-03-15 21:05:39 得分 0
如果可以,程序中每个模块的功能你们那位高手知道的,帮我分析最好了...Top
8 楼SEUU(三枝花)回复于 2006-03-15 23:30:35 得分 20
最好把你遇到的问题以及你想实现的功能详细说一下
没有注释,垃圾代码来着,不合规范啊,最少要有20%的量啊Top




