操作系统:中文WINDOWS2000
开发工具:VC6
语言:C
实践一:顺序表
- 实现原码下载
源码如下:
main.c/**/ /*
程序名称:线性表(顺序表)实现。
说明:
参考书目:<<严蔚敏-数据结构(C语言版)>>
这个程序只是完成顺序表原理的,一些简单实
现所以并不十分的完善。
设计者:高玉涵
地点: 郑州大学。
设计时间:200502026
完成时间:20050304
*/
#include < stdio.h >
#include < stdlib.h >
#include " xxb.h " /**/ /* 定义的函数 */
#include " jm1.h " /**/ /* 界面1 */
SxList sxlist; /**/ /* 顺序结构 */
int main ( void )
... {
while( SxListPrintf (&sxlist) )
...{
system ("cls"); /**//* DOS清屏 */
}
}xxb.h
/**/ /*
文件名称:xxb.h
文件说明:
定义的顺序表所需数据或函数。
*/
#define MC_MAX 8 /* 名称最大长度 */
#define SX_INIT_SIZE 3 /* 顺序表存储空间初始值。 */
#define SX_ZL 3 /* 顺序表存储空间的增量。 */
typedef struct
... {
int xh; /**//* 序号 */
char date[MC_MAX]; /**//* 日期 */
char zcmc[MC_MAX]; /**//* 支出名称 */
char srmc[MC_MAX]; /**//* 收入名称 */
float zcje; /**//* 支出金额 */
float srje; /**//* 收入金额 */
} Kzmx; /**/ /* 开支明细 */
typedef struct
... {
Kzmx *elem; /**//* 存储空间基址 */
int length; /**//* 当前长度 */
int listsize; /**//* 当前分配的存储容量(以sizeof(结构类型)为单位。 */
} SxList; /**/ /* 顺序表结构 */
/**/ /* 以下声明的是对顺序表操作的函数 */
int SxInitList (SxList * L); /**/ /* 构造一个空的顺序表 */
int SxListEmpty (SxList * L); /**/ /* 若顺序表为空返回1,否则返回0*/
int SxListLength (SxList * L); /**/ /* 获取顺序表长度 */
int SxListInsert (SxList * L, int i, Kzmx e); /**/ /* 在顺序表i位置中插入e */
int SxListDelete (SxList * L, int i); /**/ /* 在顺序表中删除i位置的数据 */
xxbfun.c
/**/ /*
文件名称:xxbfun.c
文件说明:
定义对顺序表数据结构操作所需函数。
*/
#include < stdio.h >
#include < stdlib.h >
#include " xxb.h " /**/ /* 声明的数据(函数) */
/**/ /*
构造一个空的顺序表
*/
int SxInitList (SxList * L)
... {
L->elem = (Kzmx *) malloc ( sizeof(Kzmx) * SX_INIT_SIZE ); /**//* 分配内存空间 */
if( L->elem != NULL ) /**//* 此处用了显示表达式 */
...{
L->length = 0; /**//* 空表长度为0 */
L->listsize = SX_INIT_SIZE; /**//* 初始存储容量 */
return(1);
}
printf ("Out of memory! ");
return(0); /**//* 存储分配失败 */
}
/**/ /*
初始条件:顺序表L已存在。
操作结果:0失败,非0成功(元素的个数)。
*/
int SxListLength (SxList * L)
... {
if( !SxListEmpty (L) ) /**//* 判断表是否为空表 */
...{
return( L->length );
}
else
...{
return(0);
}
}
/**/ /*
初始条件:顺序表L己存在。
操作结果:若L为空表,返回1,否则返回0。
*/
int SxListEmpty (SxList * L)
... {
if( L->elem != NULL)
...{
if( L->length == 0 )
...{
return(1); /**//* 空表 */
}
else
...{
return(0); /**//* 非空表 */
}
}
else
...{
/**//* 特别说明:
当判断表不存在时(未创建),此时返回的也是0,它和表非空所返回的值
是一样的(看来是不合适的)用户到底应该如何判断呢??
此次设计中暂不理会这个问题。知道就行了。
*/
return(0);
}
}
/**/ /*
初始条件:顺序表L已存在,1<=i<=SxListLength(L)+1.
操作结果:在L中第i个位置之前插入新的数据元素e,L的长度1。
0失败,非0成功(返回插入新数据后的表长度)。
*/
int SxListInsert (SxList * L, int i, Kzmx e)
... {
Kzmx *newbase, *q, *p ;
/**//* i值不合法。 */
if( i < 1 || i > L->length + 1 )
...{
return(0);
}
if( L->length >= L->listsize ) /**//* 当前存储容量已满,增加容量。 */
...{
newbase = (Kzmx *) realloc ( L->elem,
(L->listsize + SX_ZL) * sizeof(Kzmx) );
if( newbase != NULL)
...{
L->elem = newbase; /**//* 新基址 */
L->listsize += SX_ZL; /**//* 增加存储容量 */
}
else
...{
exit(0); /**//* 分配存储空间失败。退出! */
}
}
/**//* 因为C的下标是从0开始的,所以这里采用了i-1的操作。 */
q = &(L->elem[i - 1]) ; /**//* q为插入位置 */
for( p = &(L->elem[L->length - 1]) ; p >= q ; --p )
...{
/**//* 插入位置及之后的元素右移 */
*(p+1) = *p;
(*(p+1)).xh += 1; /**//* 序号加1 */
}
*q = e; /**//* 插入e */
L->length++ ; /**//* 表长增加1 */
return(L->length);
}
/**/ /*
初始条件:线性表L已存在且非空,0<=i<=Length (L)。
操作结果:删除L的第i个数据元素。L的长度减1。
*/
int SxListDelete (SxList * L, int i)
... {
Kzmx *p, *q;
if( i < 1 || i > L->length )
...{
return(0); /**//* i值不合法 */
}
p = &(L->elem[i - 1]); /**//* p为删除元素的位置 */
q = &(L->elem[L->length - 1]); /**//* 表尾元素的位置 */
for( ++p; p <= q; ++p )
...{
*(p-1) = *p; /**//* 被删除元素之后的元素左移 */
}
--L->length ; /**//* 表长减1 */
return(1);
}jm1.h
/**/ /*
文件名称:jm1.h
文件说明:
人机界面操作相关函数的声明。
*/
int SxListPrintf (SxList * L); /**/ /* 主菜单 */
int SxAddRecord (SxList * L); /**/ /* 添加记录 */
int SxJlInput (SxList * L); /**/ /* 操作结果:详细记录登记。*/
int SxPrintRecord (SxList * L); /**/ /* 打印顺序表中所有记录 */
int iPmStop ( void ); /**/ /* 屏幕暂停。*/
int SxJlInsert (SxList * L); /**/ /* 插入记录 */
int SxJlDelete (SxList * L); /**/ /* 删除记录 */jm1.c
/**/ /*
文件名称:jm1.c
文件说明:
顺序表操作中人机界面函数。
*/
#include < stdio.h >
#include < stdlib.h >
#include " xxb.h "
/**/ /*
主菜单.
*/
int SxListPrintf (SxList * L)
... {
int value; /**//* 保存选项值 */
printf (" ----------顺序结构实现---------- ");
printf (" | 1.添加开支记录。 | ");
printf (" | 2.插入一项记录。 | ");
printf (" | 3.删除一项记录。 | ");
printf (" | 4.显示所有记录。 | ");
printf (" | 5.保存所有记录。 | ");
printf (" | 0.退出。 | ");
printf (" --------------------------------- ");
printf (" 请选择:");
scanf ( "%d", &value); /**//* 获取输入的值 */
switch( value )
...{
case 1:
if( (SxAddRecord (L)) == 0 ) /**//* 添加新记录 */
...{
printf ("添加失败! ");
}
break;
case 2:
if( (SxJlInsert (L)) == 0 )
...{
printf ("插入失败! ");
}
break;
case 3:
SxJlDelete (L);
break;
case 4:
if( !SxPrintRecord (L) )
...{
printf ("找不到数据! ");
}
break;
case 5:
return( value ); break;
case 0:
return( value ); break;
default:
printf (" 选项错误!");
}
return( value );
}
/**/ /*
操作结果:依次向顺序表中添加记录。
0失败,非0成功(返回添加的记录数)。
*/
int SxAddRecord (SxList * L)
... {
if( SxInitList (L) ) /**//* 初始化存储空间 */
...{
/**//* 返回执行状态 */
return( SxJlInput (L) ); /**//* 详细记录登记 */
}
else
...{
return(0);
}
}
/**/ /*
插入数据。
*/
int SxJlInsert (SxList * L)
... {
int value, value1;
Kzmx e; /**//* 开支明细 */
if( L->elem != NULL )
...{
printf ("输入要在其前面添加数据的序号:");
scanf ("%d", &value);
printf ("请输入日期(yyyymmdd):");
scanf ("%s", &e.date);
printf ("支出名称(4个汉字):");
scanf ("%s", &e.zcmc);
printf ("支出金额:");
scanf ("%f", &e.zcje);
printf ("收入名称(4个汉字):");
scanf ("%s", &e.srmc);
printf ("收入金额:");
scanf ("%f", &e.srje);
e.xh = value; /**//* 序号 */
printf ("确定插入(1/0)?");
scanf ("%d", &value1); /**//* 等待用户输入 */
if( value1 == 1 )
...{
/**//* 返回执行状态 */
return(SxListInsert (L, value, e));
}
else
...{
return(0);
}
}
else
...{
return(0);
}
}
/**/ /*
操作结果:详细记录登记。
0未添加,非0成功(返回登记的记录数)。
*/
int SxJlInput (SxList * L)
... {
int value; /**//* 用户输入的值 */
int i = 0; /**//* 计数器 */
printf ("是否开始添加新记录(1/0)?");
scanf ("%d", &value);
if( value == 1 )
...{
while( value )
...{
printf ("请输入日期(yyyymmdd):");
scanf ("%s", L->elem[L->length].date);
printf ("支出名称(4个汉字):");
scanf ("%s", L->elem[L->length].zcmc);
printf ("支出金额:");
scanf ("%f", &L->elem[L->length].zcje);
printf ("收入名称(4个汉字):");
scanf ("%s", L->elem[L->length].srmc);
printf ("收入金额:");
scanf ("%f", &L->elem[L->length].srje);
L->length += 1; /**//* 表长增加1 */
/**//* C的下标是从0开始,所以此处用了减1操作 */
L->elem[L->length - 1].xh = L->length; /**//* 序号赋值 */
i++; /**//* 计数 */
printf ("是否继续添加新记录(1/0)?");
scanf ("%d", &value); /**//* 获取用户输入的值 */
}
printf (" %d个记录被添加. ", i);
while ( iPmStop () )
...{
; /**//* 空语句 */
}
return(i); /**//* 返回添加的记录数 */
}
else
...{
printf (" %d个记录被添加. ", i);
while ( iPmStop () )
...{
; /**//* 空语句 */
}
return(0);
}
}
/**/ /*
初始条件:顺序表L已存在。
操作结果:显示顺序表中所有记录,
0失败,非0成功(返回记录数)。
*/
int SxPrintRecord (SxList * L)
... {
int iLenght; /**//* 表长 */
int i; /**//* 计数器 */
if( !SxListEmpty (L) ) /**//* 判断表是否为空表 */
...{
iLenght = SxListLength (L); /**//* 获取表长 */
printf (" ----------------顺序表中全部记录-------------- ");
printf (" |序号|日 期|支出名称|支出金额|收入名称|收入金额| ");
printf (" ----------------------------------------------- ");
for(i = 0; i < iLenght; i++)
...{
printf (" |%03d|%8s|%8s|%g|%8s|%g| ",
L->elem[i].xh, L->elem[i].date, L->elem[i].zcmc,
L->elem[i].zcje, L->elem[i].srmc, L->elem[i].srje );
}
printf (" ----------------------------------------------- ");
printf (" 共%d条记录 ", iLenght);
while ( iPmStop () )/**//* 屏幕暂停 */
...{
; /**//* 空语句 */
}
return(iLenght); /**//* 返回表长 */
}
return(0);
}
/**/ /*
屏幕暂停。成功返回0,失败返回1。
*/
int iPmStop ( void )
... {
char value;
printf ("返回请输入y:");
scanf ("%c", &value);
if( value == 'y' )
...{
return(0);
}
return(1);
}
/**/ /*
删除记录。
*/
int SxJlDelete (SxList * L)
... {
int value, value1;
printf ("请输入要删除数据的序号:");
scanf ("%d", &value);
printf ("真的要删除序号是%d的数据吗(1/0)?", value);
scanf ("%d", &value1);
if( value1 == 1)
...{
if( !(SxListDelete (L, value)) )
...{
printf ("删除记录失败! ");
return(0);
}
return(1);
}
return(0);
}单链表实现原码下载地址http://bdxpublic.51.net/files/lb2.rar
源码如下:
main.c/**/ /*
程序名称:线性表(单链表)实现。
说明:
参考书目:<<严蔚敏-数据结构(C语言版)>>
这个程序只是一个对单链表,实现简单操作的程序
所以并不十分的完善。
设计者:高玉涵
地点: 郑州大学。
设计时间:20050304
完成时间:20050316
*/
#ifndef _HEADERNAME_H
#define _HEADERNAME_H 1
#include < stdio.h >
#include < stdlib.h >
#include " LinkList.h " /**/ /* 声明的数据或者函数 */
#endif
#include " jm1.h "
LNode * pHead; /**/ /* 单链表头结点 */
int main ( void )
... {
int iExit = 0; /**//* Do循环时退出条件值 */
pHead = pCreateLink (pHead); /**//* 创建链表头 */
system ("cls");
iExit = iLinkPrint (pHead);
while( iExit )
...{
system ("cls"); /**//* 清屏 */
iExit = iLinkPrint (pHead);
}
}LinkList.h
/**/ /*
文件名称:LinkList.h
文件内容:
声明线性表(单链表)实现所需的数据或函数。
*/
#define NAME_MAX 8 /**/ /* 姓名长度 */
typedef struct /**/ /* 学生信息 */
... {
int xh; /**//* 序号 */
char name[NAME_MAX]; /**//* 学生姓名 */
} Student;
typedef struct LNode /**/ /* 结点 */
... {
Student data; /**//* 数据域 */
struct LNode *pNext; /**//* 下一指针域地址 */
} LNode;
/**/ /* 以下声明的是对链表操作的函数 */
LNode * pCreateLink (LNode * Head); /**/ /* 创建新结点 */
extern int iLink_TRUE ( const LNode * pHead); /**/ /* 判断链表是否创建 */
extern int iLinkEmpty ( const LNode * pHead); /**/ /* 判断链表是否为空 */
LNode * pAddLink (LNode * pHead, Student student); /**/ /* 添加新结点到链表 */
extern int iFreeLink (LNode * pHead); /**/ /* 释放链表。*/
extern int iInsertLink (LNode * pHead, Student student, int iXh);
extern int iDeleteLink (LNode * pHead, int iXh);LinkList.c
/**/ /*
文件名称:LinkList.c
文件说明:
对单链表数据操作的函数定义。
*/
#ifndef _HEADERNAME_H
#define _HEADERNAME_H 1
#include < stdio.h >
#include < stdlib.h >
#include " LinkList.h " /**/ /* 声明的数据或者函数 */
#endif
/**/ /*
操作结果:创建一个空的链表结点。
成功返回结点地址,否则返回NULL。
*/
LNode * pCreateLink (LNode * pHead)
... {
char cInitName[] = "我是结点";
/**//* 分配存储空间。 */
pHead = (LNode *) malloc (sizeof(LNode));
if( pHead )
...{
/**//* 初始化结点数据 */
(pHead->data).xh = 0;
strcpy ((pHead->data).name, cInitName);
pHead->pNext = NULL; /**//* 下指针域地址 */
return(pHead);
}
return(NULL); /**//* 分配存储空间失败。 */
}
/**/ /*
操作说明:判断链表头是否存在。
0失败,否则返回1。
*/
extern int iLink_TRUE ( const LNode * pHead)
... {
if( pHead != NULL )
...{
return(1);
}
else
...{
return(0);
}
}
/**/ /*
操作说明:若链表头为空表时返回1,否则返回0。
*/
extern int iLinkEmpty ( const LNode * pHead)
... {
if( pHead->pNext == NULL )
...{
return(1);
}
else
...{
return(0);
}
}
/**/ /*
操作说明:添加新链到链表中。
成功返回头结点地址,否则返回NULL。
*/
LNode * pAddLink (LNode * pHead, Student student)
... {
int iCount = 0; /**//* 计数器 */
LNode *pNew = NULL; /**//* 新结点 */
LNode *pPrevious = NULL; /**//* 上一结点 */
pNew = pCreateLink (pNew); /**//* 创建新结点 */
if( pNew )
...{
/**//* 记录计数 */
while( pHead )
...{
pPrevious = pHead; /**//* 保存当前结点位置 */
pHead = pHead->pNext; /**//* 往下一结点 */
iCount++; /**//* 计数器加1 */
}
(pNew->data).xh = iCount; /**//* 序列号赋值 */
/**//* 复制名字 */
for(iCount = 0; iCount <= NAME_MAX; iCount++)
...{
(pNew->data).name[iCount] = student.name[iCount];
}
/**//* 把链表中末尾结点,所指向的下一结点位置地址(通常为NULL).
赋给刚刚创建的新结点(这时它为末尾结点)。*/
pNew->pNext = pPrevious->pNext ;
/**//* 修改原末尾结点,指向的下一结点位置地址(把新结点位置地
址赋给它)。*/
pPrevious->pNext = pNew;
return(pPrevious);
}
return(NULL);
}
/**/ /*
操作说明:释放链表。
返回释放的结点数,0表示没有需要释放的结点。
*/
extern int iFreeLink (LNode * pHead)
... {
int iCount = 0; /**//* 计数器 */
LNode *pPointer = NULL; /**//* 结点 */
while( pHead != NULL )
...{
pPointer = pHead; /**//* 设为首结点 */
pHead = pHead->pNext; /**//* 往下一结点 */
free( pPointer ); /**//* 释放占用的资源 */
iCount++; /**//* 计数器加1 */
}
return(iCount);
}
/**/ /*
操作说明:在链表指定位置插入新结点。
*/
extern int iInsertLink (LNode * pHead, Student student, int iXh)
... {
LNode *pPrevious = NULL; /**//* 上一结点 */
LNode *pNew = NULL; /**//* 新结点 */
int iCount = 0; /**//* 计数器 */
while( pHead != NULL )
...{
if( (pHead->data).xh == iXh ) break;
pPrevious = pHead;
pHead = pHead->pNext; /**//* 往下一结点 */
iCount++; /**//* 计数器加1 */
}
if( pHead != NULL ) /**//* 找到对应的序号 */
...{
pNew = pCreateLink (pNew); /**//* 创建新结点 */
/**//* 新结点数据域赋值 */
(pNew->data).xh = iCount;
for(iCount = 0; iCount <= NAME_MAX; iCount++)
...{
(pNew->data).name[iCount] = student.name[iCount];
}
/**//* 交换指针域指向的位置 */
pNew->pNext = pHead;
pPrevious->pNext = pNew; /**//* 指向新结点 */
while( pNew->pNext )
...{
pNew = pNew->pNext; /**//* 往下一结 */
(pNew->data).xh++; /**//* 序号加1 */
}
return(1);
}
else
...{
printf ("序号非法!");
return(0);
}
}
/**/ /*
操作说明:在链表中删除指定的结点。
*/
extern int iDeleteLink (LNode * pHead, int iXh)
... {
LNode *pPrevious = NULL; /**//* 上一结点 */
while( pHead )
...{
if( (pHead->data).xh == iXh ) break;
pPrevious = pHead;
pHead = pHead->pNext; /**//* 往下一结点 */
}
if( pHead )
...{
pPrevious->pNext = pHead->pNext;
free(pHead); /**//* 释放占用的资源 */
return(1);
}
return(0);
}
jm1.h
/**/ /*
文件名称:jm1.h
文件说明:
单链表操作中所需的人机界面交互函数的声明。
*/
extern int iLinkPrint (LNode * pHead); /**/ /* 与用户交互的主界面 */
extern int iAddRecord (LNode * pHead); /**/ /* 添加新记录 */
extern int iPmStop ( void ); /**/ /* 屏幕暂停 */
extern int iPrintRecordList ( const LNode * pHead); /**/ /* 打印记录列表 */
extern int iInsertRecord (LNode * pHead);
extern int iDeleteRecord (LNode * pHead);jm1.c
/**/ /*
文件名称:jm1.c
文件内容:
单链表操作中与用户交互的人机界面函数。
*/
#ifndef _HEADERNAME_H
#define _HEADERNAME_H 1
#include < stdio.h >
#include < stdlib.h >
#include " LinkList.h " /**/ /* 声明的数据或者函数 */
#endif
/**/ /*
主菜单.
*/
extern int iLinkPrint (LNode * pHead)
... {
int value; /**//* 保存选项值 */
int iCount; /**//* 计数器 */
printf (" ---------单链表结构实现---------- ");
printf (" | 1.添加学生记录。 | ");
printf (" | 2.插入一项记录。 | ");
printf (" | 3.删除一项记录。 | ");
printf (" | 4.显示所有记录。 | ");
printf (" | 5.------------。 | ");
printf (" | 0.退出。 | ");
printf (" --------------------------------- ");
printf (" 请选择:");
scanf ( "%d", &value); /**//* 获取输入的值 */
switch( value )
...{
case 1:
if( iAddRecord (pHead) == 0 )
...{
printf ("添加新记录失败! ");
}
iPmStop (); /**//* 暂停 */
break;
case 2:
if( iInsertRecord (pHead) == 0 )
...{
printf ("插入新记录失败!");
}
iPmStop (); /**//* 暂停 */
break;
case 3:
if( iDeleteRecord (pHead) == 0 )
...{
printf ("删除记录失败!");
}
iPmStop (); /**//* 暂停 */
break;
case 4:
iPrintRecordList (pHead);
iPmStop (); /**//* 暂停 */
break;
case 5:
break;
case 0:
iCount = iFreeLink (pHead);
if( iCount == 0 )
...{
printf ("链表不存在!");
}
else
...{
printf ("共有%d个结点被释放。", iCount);
}
iPmStop (); /**//* 暂停 */
break;
default:
printf (" 选项错误!");
iPmStop (); /**//* 暂停 */
}
return( value );
}
/**/ /*
操作说明:添加新记录(结点)到链表中。
成功返回1,否则返回0。
*/
extern int iAddRecord (LNode * pHead)
... {
int value = 0; /**//* 保存用户输入的值 */
Student student; /**//* 学生信息 */
printf ("请输入学生姓名(4个汉字):");
scanf ("%s", &student.name);
printf ("确定(1/0):");
scanf ("%d", &value);
if( value == 1 )
...{
/**//* 添加新结点 */
pHead = pAddLink (pHead, student);
if( pHead )
...{
return(1);
}
return(0);
}
return(0);
}
/**/ /*
操作说明:显示所有链表中的记录。
成功返回记录数,否则返回0。
*/
extern int iPrintRecordList ( const LNode * pHead)
... {
int iCount = 0; /**//* 计数器 */
LNode *pPointer; /**//*节点声明 */
if( iLink_TRUE (pHead) == 1) /**//* 链表已创建 */
...{
if( iLinkEmpty (pHead) == 0 ) /**//* 链表非空表时。*/
...{
pPointer = pHead->pNext ; /**//* 设为首结点(指向第1个记录位置) */
while( pPointer )
...{
printf ("序号:%d", (pPointer->data).xh);
printf ("学生姓名:%s ", (pPointer->data).name);
pPointer = pPointer->pNext ; /**//* 往下一结点 */
iCount++;
}
printf ("共%d条记录。", iCount);
return(iCount);
}
else
...{
printf ("链表是空表!");
return(0);
}
}
else
...{
printf ("链表未创建!");
return(0);
}
return(0);
}
/**/ /*
屏幕暂停。成功返回0,失败返回1。
*/
extern int iPmStop ( void )
... {
char key;
printf (" 退出(y):");
scanf ("%c", &key);
if( key == 'y' )
...{
return(0);
}
else
...{
while( 1 )
...{
scanf ("%c", &key);
if( key == 'y' )
...{
return(0);
}
}
}
}
/**/ /*
操作说明:在链表指定位置中插入新数据。
*/
extern int iInsertRecord (LNode * pHead)
... {
Student student; /**//* 学生信息 */
int iKeyValue, iKeyValue1; /**//* 用户输入的值 */
int iXh; /**//* 在其前插入新数据的‘序号’*/
if( iLink_TRUE (pHead) == 0 ) /**//* 链表未创建 */
...{
printf ("链表未创建。");
return(0);
}
if( iLinkEmpty (pHead) == 1 ) /**//* 链表是空表。*/
...{
printf ("链表是空表。");
return(0);
}
printf( "是否准备插入新数据(1/0)?");
scanf ("%d", &iKeyValue);
if( iKeyValue == 1 )
...{
printf ("之后插入新数据的序号:");
scanf ("%d", &iXh);
printf ("请输入学生姓名(4个汉字):");
scanf ("%s", &student.name);
printf ("确定(1/0)?");
scanf ("%d", &iKeyValue1);
if( iKeyValue1 == 1 )
...{
if( iXh != 0 )
...{
if( iInsertLink (pHead, student, iXh) )
...{
return(1);
}
return(0);
}
else
...{
printf ("序号非法!");
return(0);
}
}
return(0);
}
return(0);
}
/**/ /*
操作说明:在链表中删除指定的数据。
*/
extern int iDeleteRecord (LNode * pHead)
... {
int iKeyValue, iKeyValue1; /**//* 用户输入的值 */
int iXh; /**//* 要删除数据的‘序号’*/
if( iLink_TRUE (pHead) == 0 ) /**//* 链表未创建 */
...{
printf ("链表未创建。");
return(0);
}
if( iLinkEmpty (pHead) == 1 ) /**//* 链表是空表。*/
...{
printf ("链表是空表。");
return(0);
}
printf( "是否准备删除数据(1/0)?");
scanf ("%d", &iKeyValue);
if( iKeyValue == 1 )
...{
printf ("要删除数据的序号:");
scanf ("%d", &iXh);
printf ("确定(1/0)?");
scanf ("%d", &iKeyValue1);
if( iKeyValue1 == 1 )
...{
if( iXh != 0 )
...{
if( iDeleteLink (pHead, iXh) )
...{
return(1);
}
return(0);
}
else
...{
printf ("序号非法!");
return(0);
}
}
return(0);
}
return(0);
}未完待续......