C语言实现数据结构:线性表

第三周作业

作业题目1:

程序运行结果截图,需测试各种情况。写出测试过程中遇到的主要问题及所采用的解决措施。

运行结果截图: 

 

 

主要问题:指针的&和*用法不清楚

解决办法:多次进行调试,最终尝试得到结果

代码:

gloabledef.h

#pragma once
#include<string.h>
#include<ctype.h>
#include<malloc.h> /* malloc()等 */
#include<limits.h> /* INT_MAX等 */
#include<stdio.h> /* EOF(=^Z或F6),NULL */
#include<stdlib.h> /* atoi() */
#include<io.h> /* eof() */
#include<math.h> /* floor(),ceil(),abs() */
#include<process.h> /* exit() */
#define OK 1
#define ERROR 0
//#define OVERFLOW -2
#define INITSIZE 100			//顺序表可能达到的最大长度
#define TRUE 1
#define FALSE 0
typedef int Status; //Status 是函数返回值类型,其值是函数结果状态代码。
typedef int ElemType; //ElemType 为可定义的数据类型,此设为int类型

Sqlist.h

#pragma once
#include <stdio.h>
#include <stdlib.h>
#include "gloabledef.h"

typedef struct
{
	ElemType* data;/*存储空间的基地址*/
	int length;   /*表的长度(已存入的元素个数)*/
	int listsize;  /*当前存储空间的容量(能够存入的元素个数)*/
}sqlist;

int InitList(sqlist* L);
int GetLen(sqlist* L);
int GetElem(sqlist* L, int i, ElemType* e);
int Locate(sqlist* L, ElemType x);
void ClearList(sqlist* L);
int Insert(sqlist* L, int i, ElemType item);
void againMalloc(sqlist* L);
int DeleteElem(sqlist* L, int i);
void SqlistTest();
void OutputList(sqlist L);
void CreateSqlist(sqlist* L);
int m;

Sqlist.c

#include "Sqlist.h"
int InitList(sqlist* L)
{
	/* 存储空间初始化 */
	L->data = malloc(sizeof(ElemType) * INITSIZE);//补全代码,申请INITSIZE大小空间代码
	
	if (!L->data) {
		printf("动态存储分配失败!\n");
		return FALSE; /*执行此函数则中止程序运行*/
	}
	L->length = 0;   /* 长度为0 */
	L->listsize = INITSIZE; /* 当前存储容量初始化 */
	return TRUE;
}

int Ge
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值