24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 905  |  回复: 4

雪山冰锋

金虫 (职业作家)

[求助] 时间紧迫,在线等,明天要啊 已有1人参与

#include<stdio.h>
#include<malloc.h>
#define MaxSize 100
typedef char ElemType;
typedef struct
{
  ElemType data[MaxSize];
  int length;
}SqList;

void InitList(SqList *&L);
int ListInsert(SqList *&L,int i,ElemType e);
int ListEmpty(SqList *L);
void DispList(SqList *L);
int ListLength(SqList *L);
int GetElem(SqList *L,int i,ElemType &e);
int LocateElem(SqList *L,ElemType e);
void unionList(SqList *LA,SqList *LB);

void main()
{
SqList *LA,*LB;
printf("初始化顺序表LA\n";
InitList(LA);
printf("依次采用尾插法插入a,b,c,d,e元素\n";
ListInsert(LA,1,'a');
ListInsert(LA,2,'b');
ListInsert(LA,3,'c');
ListInsert(LA,4,'d');
ListInsert(LA,5,'e');
printf(" 输出线性表LA:";
DispList(LA);
printf("初始化顺序表LB\n";
InitList(LB);
printf("依次采用尾插法插入a,v,e,h,k元素\n";
ListInsert(LB,1,'a');
ListInsert(LB,2,'v');
ListInsert(LB,3,'e');
ListInsert(LB,4,'h');
ListInsert(LB,5,'k');
printf(" 输出线性表LB:";
DispList(LB);
unionList(LA,LB);
printf(" 输出集合LA:";
DispList(LA);
}

void InitList(SqList *&L)
{
          L=(SqList *)malloc(sizeof(SqList));
        L->length=0;
}
int ListInsert(SqList *&L,int i,ElemType e)
{
        int j;
        if(i<1||i>L->length+1)
                return 0;
        i--;
        for(j=L->length;j>i;j--)
                L->data[j]=L->data[j-1];
        L->data=e;
        L->length++;
        return 1;
}

int ListEmpty(SqList *L)
{
        return(L->length==0);
}

void DispList(SqList *L)
{
        int i;
        if(ListEmpty(L))return;
        for(i=0;i<L->length;i++)
                printf("%c",L->data);
        printf("\n";
}

int ListLength(SqList *L)
{
        return(L->length);
}

int GetElem(SqList *L,int i,ElemType &e)
{
        if(i<1 || i>L->length)
                return 0;
        e=L->data[i-1];
        return 1;
}

int LocateElem(SqList *L,ElemType e)
{
        int i=0;
        while(i<L->length && L->data!=e)i++;
        if(i>=L->length)
                return 0;
        else
                return i+1;
}

void unionList(SqList *LA,SqList *LB)
{
ElemType e;
LA->length = ListLength(LA);
LB->length = ListLength(LB);
for(int i = 1;i<= LB->length;i++){
  GetElem(LB,i,e);
  if(!LocateElem(LA,e)){
          ListInsert(LA, ++LA->length,e);
  }
}
}
请帮忙看看哪里有问题

时间紧迫,在线等,明天要啊
_{~$6%B8N)DNQ}]8KK]3Q)Y.jpg
回复此楼
南朝四百八十寺,多少楼台烟雨中
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cardinalree

至尊木虫 (著名写手)

我学的VB

[ 发自手机版 http://muchong.com/3g ]
2楼2014-12-25 19:52:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

雪山冰锋

金虫 (职业作家)

引用回帖:
2楼: Originally posted by cardinalree at 2014-12-25 19:52:47
我学的VB

能看出问题不
南朝四百八十寺,多少楼台烟雨中
3楼2014-12-26 19:35:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cardinalree

至尊木虫 (著名写手)

语法不一样,爱莫能助%0%0%0%0

[ 发自手机版 http://muchong.com/3g ]
4楼2014-12-27 09:06:53
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

chempursuer

新虫 (初入文坛)

【答案】应助回帖

你的算法不对,你应该每次insert变量之后,就重新给LA动态分配一次内存,那样的话,LA才代表真正的线性表,而不是碰运气在内存里通过访问了不属于LA本身的内存空间
开心每一天
5楼2014-12-31 22:13:00
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 雪山冰锋 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 请问共同通讯和共同一作的认可度问题 10+3 psa1234 2026-04-01 4/200 2026-04-02 13:24 by psa1234
[考研] 286分调剂 +20 Faune 2026-03-30 22/1100 2026-04-02 13:24 by clyblh
[考研] 材料科学与工程调剂 +18 深V宿舍吧 2026-03-30 19/950 2026-04-02 10:28 by sanrepian
[考研] 一志愿厦门大学化学工程(专硕)-数二英二406分-求调剂 +5 厦大化工 2026-04-01 5/250 2026-04-02 10:03 by jp9609
[考研] 一志愿211,335分,0856,求调剂院校和导师 +14 倾____萧 2026-03-27 15/750 2026-04-02 09:21 by olim
[考研] 085602化学工程268分蹲调剂 +8 月照花林。 2026-04-01 8/400 2026-04-01 22:08 by 无际的草原
[考研] 353求调剂 +4 拉钩不许变 2026-04-01 4/200 2026-04-01 18:10 by 记事本2026
[考研] 350求调剂 +7 阿佳~ 2026-03-31 7/350 2026-04-01 16:12 by yanflower7133
[考研] 一志愿北京科技大学085601材料工程英一数二初试总分335求调剂 +5 双马尾痞老板2 2026-03-31 5/250 2026-04-01 09:04 by oooqiao
[考研] 254材料与化工求调剂 +3 翰冬林楠 2026-03-30 4/200 2026-03-31 17:53 by yishunmin
[考研] 江苏苏北高校诚邀调剂同学 +3 zzll406 2026-03-31 3/150 2026-03-31 16:54 by 及时行乐fan
[考研] 考研调剂求助 +7 13287130938 2026-03-31 7/350 2026-03-31 16:39 by 690616278
[考研] 282求调剂 不挑专业 求收留 +4 Yam. 2026-03-30 5/250 2026-03-31 14:41 by 王亮_大连医科大
[考研] 一志愿中海洋材料357 +4 麦恩莉. 2026-03-30 4/200 2026-03-31 14:35 by 记事本2026
[考研] 334求调剂 +7 Trying] 2026-03-31 7/350 2026-03-31 12:33 by 无际的草原
[考研] 本科211总分289,08工学真心求调剂 +3 utopiaE 2026-03-30 3/150 2026-03-30 23:42 by ms629
[考研] 0703化学321分求调剂 +10 三dd. 2026-03-30 11/550 2026-03-30 19:24 by markhwc
[考研] 298求调剂 +3 种圣赐 2026-03-29 3/150 2026-03-29 12:06 by longlotian
[考研] 308求调剂 +7 墨墨漠 2026-03-27 7/350 2026-03-28 07:43 by 热情沙漠
[考研] 调剂 +3 李嘉图·S·路 2026-03-27 3/150 2026-03-27 11:19 by wangjy2002
信息提示
请填处理意见