搜索
首页 电脑/网络 程序设计 C/C++

修改一下程序 急急急。。。。

  数据结构算法用c语言实现,但一直搞不清要怎么写,下面是我的一个程序,错了很多,希望能帮我改一下,最后功能和这个一样,构造一个空的线性表,然后输入一个线性表,再在第i个位置插入新元素e。#include#include#include#include LIST_INIT_SIZE 100#include LISTINCREMENT 10#include OK 1#include OVERFLOW -1typedef int ElemType; typedef int Status; typedef struct{ ElemType *elem; int length; int listsize;}SqList;Status InitList_Sq(SqList &L){ L。
  elem = (ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType)); if(!L。elem )exit(OVERFLOW); L。length = 0; L。listsize =LIST_INIT_SIZE; return OK;}Status ListInsert_Sq(SqList &L,int i,ElemType e){ if(iL。
  length +1)return ERROR; if(L。length >=L。listsize ){ newbase=(ElemType *) realloc(L。elem ,(L。listsize +LISTINCREMENT)*sizeof(ElemType)); if(!newbase)exit(OVERFLOW); L。
  elem = newbase; L。listsize += LISTINCREMENT; } q=&(L。elem [i -1]); for(p=&(L。elem [L。length -1]);p>=q;--p)*(p+1)=*p; *q=e; ++L。
  length ; return OK;}main(){ int n; SqList a; ElemType e=6; scanf("%d",&n); for(i=0,i<n,i++){ scanf("%d",a[i]); } for(i=0,i<n,i++){ printf("%d",a[i]); } ListInsert_Sq(a,n,e); return 0;}。
  

全部回答

2009-10-07

0 0
    你也太狠了吧?#include OK 1? #include #include #define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define OK 1 #define OVERFLOW -1 #define ERROR 0 typedef int ElemType; typedef int Status; typedef struct{ ElemType *elem; int length; int listsize; }SqList; Status InitList_Sq(SqList&L){ L。
    elem = (ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType)); if(!L。elem )exit(OVERFLOW); L。
  length = 0; L。listsize =LIST_INIT_SIZE; return OK; } Status ListInsert_Sq(SqList &L,int i,ElemType e){ ElemType*newbase,*q,*p; if(iL。
    length +1)return ERROR; if(L。length >=L。listsize ){ newbase=(ElemType *) realloc(L。
  elem ,(L。listsize +LISTINCREMENT)*sizeof(ElemType)); if(!newbase)exit(OVERFLOW); L。  elem = newbase; L。
  listsize += LISTINCREMENT; } q=&(L。elem [i -1]); for(p=&(L。elem [L。length -1]);p>=q;--p)*(p+1)=*p; *q=e; ++L。
    length ; return OK; } void main(){ int n,i,b[100]; SqList a; ElemType e=6; InitList_Sq(a); scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",b[i]); ListInsert_Sq(a,i+1,b[i]); } for(i=0;i<n;i++)printf("%d",b[i]); ListInsert_Sq(a,n,e); } 另外,这段代码中有引用参数(像SqList&L),所以一定要在C++中做,也就是说如果你在vc++中做的话,添加文件时,文件名后不能加后缀名。
    c!。

类似问题换一批

热点推荐

热度TOP

相关推荐
加载中...

热点搜索 换一换

电脑/网络
C/C++
硬件
电脑装机
程序设计
互联网
操作系统/系统故障
笔记本电脑
反病毒
百度
软件
程序设计
C/C++
VB
数据库
汇编语言
JAVA相关
VC++
C#/.NET
其他编程语言
C/C++
C/C++
举报
举报原因(必选):
取消确定举报