免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1011 | 回复: 1
打印 上一主题 下一主题

新手问题...HELP... [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-18 23:22 |只看该作者 |倒序浏览
//线性表的插入
#include <stdio.h>
#include <stdlib.h>
#define list_init_size 100
#define listincrement 10
typedef struct         // 定义线性表..
{
        int *elem ;
        int listlength ;
        int listsize ;

} sqlist ;

int initlist(sqlist &l)              //键个空表...
{
        l->elem=(int *)malloc(list_init_size*sizeof(int));   //开空间..
        if(l->elem==NULL)
                return 0;
        l->listlength=NULL;            // 长度为0

        l->listsize=list_init_size;       //初始分配大小..
        return 1;

}

int destroylist(sqlist *l)          //销毁表...
{
        free(l->elem);
        l->elem=NULL;
        return 1;

}

int clearlist (sqlist *l)   //变为空..
{
        l->elem=NULL;
        l->listlength=NULL;
        return 1;


}

int listempty (sqlist *l)         //表为空返回1  ...否0
{

        if(l->elem==NULL&&l->listlength==NULL)
                return 1 ;
        return 0;

}

int listlength (sqlist *l)    //表长大小...
{

        return(l->listlength);

}

int getelem(sqlist l,int i,int *e)   ////用e返回l 表中第i个元素...
{
        if(i>=1&&i<=l.listlength)
                *e=l.elem[i-1];


}

int priorelem (sqlist &l,int cur_e,int &pre_e) // 用pre_e返回..L表中cur_e的前驱..
{
        int i=0;
        while (l->elem[i]!=cur_e)
                i++;
        *pre_e=l->elem[i-1];
       
}

int nextelem (sqlist l;int cur_e;int &next_e) // 用next返回..L表中cur_e的前驱..
{
        int i=0;
        while (l.elem[i]!=cur_e)
                i++;
        *next_e=l.elem[i+1];


}   

int listinsert(sqlist &l;int i;int *e)   //插入...
{
        int m=0;
        while(m<10)
        {
                scanf("%d",&(l->elem[m]));
               
       
        }
       

        if(l->listlength>=l->listsize)
        {*elem=(int *)relloc(l->elem,(listsize+listincrement)*sizeof(int));
        if(*elem==UNLL)
                return 0;
        l->listsize+=listincrement;
        }
        for(int j=l->listlength-1;j>=i;j--)
        {
                l->elem[j+1]=l->elem[j]

       
       
        }
        l->elem[j]=*e;


}

main()
{

        sqlist a;
        int b,c,e,d,f,i;

        initlist(&a);
        destroylist(&a);
        clearlist(&a);
        listempty(&a);
        listlength(&a);
        getelem(a,7,&c);
        priorelem(&a,6,&d);
        nextelem(&a,5,&e);
        listinsert(&a,4,&f);
        printf("%d\n",c);
        printf("%d\n",d);
        printf("%d\n",e);
        printf("%d\n",f);
        for(i=0;i<=listlength-1;i++)
                printf("%5d",l->elem[i]);


}

错了好多啊.....救命啊..谢谢各位高手了啊...


CUO

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2007-03-18 23:29 |只看该作者
哪里错了,
总不能扔一个程序,
啥也不说明一下吧?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP