线性表的基本操作与实现
typedef int ElemType; typedef struct {
int top; /*类型定义*/ ElemType *base; int stacksize; }sqstack;
void initstack(sqstack *s) {
s->base=(ElemType
*)malloc(INITSIZE*sizeof(ElemType)); //建一个空栈 s->top=0;
s->stacksize=INITSIZE; } 4.
#include #include #define size 1200
int m=-1,n=-1,j=0,k=0,l=0;
typedef struct{
long stack[size]; //类型定义 int top; }sequenstack;
void initstack(sequenstack *s) {
s->top =-1; //创建一个空栈 }
int stackempty(sequenstack *s) {
if(s->top =-1) //判断栈是否为空 return 1; else return 0; }
六、运行结果、测试分析与讨论:
1. please enter the data:1 2 3 4
运行结果:the length is 3: 2 3 4 the length is 2: 3 4 the length is 1: 4 the length is 0:
2,please enter the data:1 2 3 4 5 please enter the data: 2 3 4 5 6 运行结果:合并为 :2 3 4 5
1复习C语言中指针的用法,特别是结构体的指针的用法;
2.理解线性表中各种数据结构的基本概念以及相关操作的实现方法;主要包括:顺序表、链表、循环链表等;
3.掌握应用线性表解决实际问题的一般方法和步骤。
4.学习到一个程序是有好多基本函数组成的,每个函数都是程序的重要组成部分。要打好扎实的基础。 5.熟练的运用线性表,栈和结构体指针的用法。 6.感觉到编程的难。要多看多读多编写程序。