用vc++6.0怎么一步一步的编写程序?
//线性表的动态分配顺序存储结构# include "stdlib.h"
# include "stdio.h"
//函数结果状态代码
# define TURE 1
# define FALSE 0
# define OK 1
# define ERROR 0
# define INFEASIBLE -1
# 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;//当前分配的存储容量
// (以sizeof(ElemType)为单位)
}sqlist;
Status InitList(sqlist &L,int elem_number)
{//构造一个空线性表L
if (elem_number> List_init_size ) return ERROR;
L.elem=(ElemType *) malloc(elem_number*sizeof(ElemType));
if (!L.elem) exit(OVERFLOW);
L.length=0;
L.listsize= elem_number;
return OK;
}
//在线性表中插入一个元素
Status Listinsert_sq(sqlist &L,int i,ElemType e) {
ElemType *p,*q,*newbase;
if (i<1 || i>L.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;
}// listinsert_sq;
//在线性珍中删除第i个元素,其结果保留在e中
Status Listdelete_sq(sqlist &l,int i,ElemType &e)
{
ElemType *p,*q;
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;
}// listdelete_sq;
void OutPutList(sqlist l)
{
int j;
for(j=0;j<l.length;j++)
printf("%d ",l.elem[j]);
printf("\n");
}
void main()
{
int n,e,i,s,m;
sqlist l;
printf("请输入线性表的元素个数:");
scanf("%d",&n);
InitList(l,n);
printf("请输入线性表的元素:");
for(i=0;i<n;i++)
scanf("%d",&l.elem[i]);
l.length=n;
OutPutList(l);
printf("请输入插入的位置和插入的元素:");
scanf("%d%d",&s,&e);
Listinsert_sq(l,s,e);
OutPutList(l);
printf("请输入删除元素的位置");
scanf("%d",&m);
Listdelete_sq(l,i,e);
OutPutList(l);
printf("程序结束!\n");
}
怎么运行哦?
比较菜的问题 希望高手解答下..
我用VC++6.0 新建 文件 C++source file 把上面的程序粘上去 出线错误..