- 博客(0)
- 资源 (3)
- 收藏
- 关注
数据结构实践指导代码.rar
很好的源代码哦,学好数据结构的必备代码
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量
#define LISTINCREMENT 10//线性表存储空间的分配增量
#define OK 1
#define ERROR 0
#define OVERFLOW 0
typedef struct
{
int *elem;
int length;//当前长度
int listsize;//当前分配的存储容量
}SqList;
int InitList_Sq(SqList &L) //生成一个空的顺序表
{
L.elem = (int *)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem)
exit(OVERFLOW);
L.length = 0;
L.listsize = LIST_INIT_SIZE;
return OK;
}
#include "D:\hy\SqList\SqList.h"
int CreateList_Sq(SqList &L)//建立顺序表
{
int i;
printf("Input the datas:");
for(i=0;i<L.length;i++)
scanf("%d",&L.elem[i]);
return OK;
}
void main()
{
//clrscr();//清屏
int i,n;
SqList L;
InitList_Sq(L);
printf("\nInput the length of the list L:");
scanf("%d",&n);//输入顺序表的长度
L.length = n;
CreateList_Sq(L);
printf("Output the datas:"); //输出顺序表
for(i=0;i<L.length;i++)
printf("%d ",L.elem[i]);
}
2010-07-15
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人