| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2001 人关注过本帖
标题:看不懂,也不知哪错了,求大神帮我备注一下意思,谢谢,谢谢
只看楼主 加入收藏
s524250262
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2015-5-26
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:1 
看不懂,也不知哪错了,求大神帮我备注一下意思,谢谢,谢谢
#include <stdio.h>
#include <stdlib.h>

#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;


#define  LIST_INIT_SIZE     100  
#define  LISTINCREMENT    10

typedef  struct {
    ElemType *elem;   
    int length;   
    int listsize;  
 }SqList;  
 
Status InitList( SqList &L) {
     L.elem=(ElemType*)malloc(LIST_INIT_sizeof(EiemType));
     if(!L.elem)exit(OVERFLOW);
     L.length=0;
     L.listsize=LIST_INIT_SIZE;
     return OK;
}
 
void TraverList(SqList L)//输出线性表中的元素
{
    int i;
  for (i=0;i<L.length;i++)
  {
     printf("%d\t",L.elem[i]);
  }
}

Status ListInsert(SqList &L, int i, ElemType e) {
   
       if(i<1||i>L.length+1) return ERROR;
       q=&(L.elem[i-1]);  
       for(p=&(L.elem[L.length-1]); p>=q; --p)
        *(p+1)=*p;
       *q=e;  
       ++l.length;
        return OK;
   
   
}
 
Status ListDelete(SqList &L, int i, ElemType &e) {
    if(i<1||i>L.length+1) return ERROR;  
    p=&(L.elem[i-1]);
    e=*p  
    q=L.elem+L.length-1;
    for(++p;p<=q;++p)
    *(p-1)=*p;
    --L.length;
     return OK;

}

int LocateElem(SqList L, ElemType e) {
}

void main()
{   
   SqList L;
   int i,choose;
   ElemType e;
   if (InitList(L)==OVERFLOW) {printf("\nOVERFLOW" );return ;}
  
   TraverList(L);
   
  do{
     printf("选择要执行的基本操作:\n1:插入元素;\n2:删除元素;\n3:查找元素;\n");
     scanf("%d",&choose);
    switch(choose){
        case 1:
            printf("输入要插入元素的位置和值:\n");
            scanf("%d%d",&i,&e);
            if (ListInsert(L,i,e)==OK) TraverList(L);
            else printf("不能插入!\n");
            break;
        case 2:
            printf("输入要删除元素的位置:\n");
            scanf("%d",&i);
            if(ListDelete(L,i,e)==OK) TraverList(L);
            else printf("删除位置不合法。\n");
            break;
        case 3:
            printf("输入要查找元素的值:\n");
            scanf("%d",&e);
            if(LocateElem(L,e))
            printf("该元素的位置是第 %d位!\n",LocateElem(L,e));
            else
            printf("该元素不存在!\n");
            break;
        default:
            printf("操作结束!");
            return;
    }
   }while(1);
  return;
 }
搜索更多相关主题的帖子: include return 
2015-10-23 12:40
FirstC
Rank: 2
等 级:论坛游民
帖 子:1
专家分:20
注 册:2015-10-25
收藏
得分:20 
程序代码:
#include <stdio.h>
#include <stdlib.h>

#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;


#define  LIST_INIT_SIZE     100  
#define  LISTINCREMENT    10 

typedef  struct {
    ElemType *elem;    
    int length;   
    int listsize;  
}SqList;  

Status InitList( SqList &L) {
     L.elem=(ElemType*)malloc(sizeof(ElemType));//     L.elem=(ElemType*)malloc(LIST_INIT_sizeof(ElemType));
     if(!L.elem)exit(OVERFLOW);
     L.length=0;
     L.listsize=LIST_INIT_SIZE;
     return OK;
}

void TraverList(SqList L)//输出线性表中的元素
{
    int i;
  for (i=0;i<L.length;i++)
  {
     printf("%d\t",L.elem[i]);
  }
}

Status ListInsert(SqList &L, int i, ElemType e) {
    ElemType *q,*p;//新建
   
       if(i<1||i>L.length+1) return ERROR; 
       q=&(L.elem[i-1]);  
       for(p=&(L.elem[L.length-1]); p>=q; --p) 
        *(p+1)=*p; 
       *q=e;  
       ++L.length;                   //       ++l.length; 
        return OK; 
    
   
}

Status ListDelete(SqList &L, int i, ElemType e) {        //Status ListDelete(SqList &L, int i, ElemType &e) {
   ElemType *q,*p;//新建
    if(i<1||i>L.length+1) return ERROR;  
    p=&(L.elem[i-1]); 
    e=*p;       //   e=*p
    q=L.elem+L.length-1; 
    for(++p;p<=q;++p) 
    *(p-1)=*p; 
    --L.length; 
     return OK; 

}

int LocateElem(SqList L, ElemType e) {
    return 0;//加了return 0;调试通过,此处函数自己补充啊
}

void main()
{   
   SqList L;
   int i,choose;
   ElemType e;
   if (InitList(L)==OVERFLOW) {printf("\nOVERFLOW" );return ;}
  
   TraverList(L);
   
  do{
     printf("选择要执行的基本操作:\n1:插入元素;\n2:删除元素;\n3:查找元素;\n");
     scanf("%d",&choose);
    switch(choose){
        case 1:
            printf("输入要插入元素的位置和值:\n");
            scanf("%d%d",&i,&e);
            if (ListInsert(L,i,e)==OK) TraverList(L);
            else printf("不能插入!\n");
            break;
        case 2:
            printf("输入要删除元素的位置:\n");
            scanf("%d",&i);
            if(ListDelete(L,i,e)==OK) TraverList(L);
            else printf("删除位置不合法。\n");
            break;
        case 3:
            printf("输入要查找元素的值:\n");
            scanf("%d",&e);
            if(LocateElem(L,e))
            printf("该元素的位置是第 %d位!\n",LocateElem(L,e));
            else
            printf("该元素不存在!\n");
            break;
        default:
            printf("操作结束!");
            return;
    }
   }while(1);
  return 0;
}

2015-10-25 21:32
快速回复:看不懂,也不知哪错了,求大神帮我备注一下意思,谢谢,谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045594 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved