>凡事网 导航

十万火急~在线等~堆栈在链式存储上的操作(包括头文件,功能函数文件,主函数文件)

2024-07-04m.fan-pin.com
C++函数头文件有哪些?~

C、传统 C++

#include <assert.h> //设定插入点
#include <ctype.h> //字符处理
#include <errno.h> //定义错误码
#include <float.h> //浮点数处理
#include <fstream.h> //文件输入/输出
#include <iomanip.h> //参数化输入/输出
#include <iostream.h> //数据流输入/输出
#include <limits.h> //定义各种数据类型最值常量
#include <locale.h> //定义本地化函数
#include <math.h> //定义数学函数
#include <stdio.h> //定义输入/输出函数
#include <stdlib.h> //定义杂项函数及内存分配函数
#include <string.h> //字符串处理
#include <strstrea.h> //基于数组的输入/输出
#include <time.h> //定义关于时间的函数
#include <wchar.h> //宽字符处理及输入/输出
#include <wctype.h> //宽字符分类

//////////////////////////////////////////////////////////////////////////

标准 C++ (同上的不再注释)

#include <algorithm> //STL 通用算法
#include <bitset> //STL 位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex> //复数类
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque> //STL 双端队列容器
#include <exception> //异常处理类
#include <fstream>
#include <functional> //STL 定义运算函数(代替运算符)
#include <limits>
#include <list> //STL 线性列表容器
#include <map> //STL 映射容器
#include <iomanip>
#include <ios> //基本输入/输出支持
#include <iosfwd> //输入/输出系统使用的前置声明
#include <iostream>
#include <istream> //基本输入流
#include <ostream> //基本输出流
#include <queue> //STL 队列容器
#include <set> //STL 集合容器
#include <sstream> //基于字符串的流
#include <stack> //STL 堆栈容器
#include <stdexcept> //标准异常类
#include <streambuf> //底层输入/输出支持
#include <string> //字符串类
#include <utility> //STL 通用模板类
#include <vector> //STL 动态数组容器
#include <cwchar>
#include <cwctype>

using namespace std;

//////////////////////////////////////////////////////////////////////////

C99 增加

#include <complex.h> //复数处理
#include <fenv.h> //浮点环境
#include <inttypes.h> //整数格式转换
#include <stdbool.h> //布尔环境
#include <stdint.h> //整型环境
#include <tgmath.h> //通用类型数学宏

C头文件大全



分类函数,所在函数库为ctype.h

int isalpha(int ch) 若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0

int isalnum(int ch) 若ch是字母('A'-'Z','a'-'z')或数字('0'-'9')

返回非0值,否则返回0

int isascii(int ch) 若ch是字符(ASCII码中的0-127)返回非0值,否则返回0

int iscntrl(int ch) 若ch是作废字符(0x7F)或普通控制字符(0x00-0x1F)

返回非0值,否则返回0

int isdigit(int ch) 若ch是数字('0'-'9')返回非0值,否则返回0

int isgraph(int ch) 若ch是可打印字符(不含空格)(0x21-0x7E)返回非0值,否则返回0

int islower(int ch) 若ch是小写字母('a'-'z')返回非0值,否则返回0

int isprint(int ch) 若ch是可打印字符(含空格)(0x20-0x7E)返回非0值,否则返回0

int ispunct(int ch) 若ch是标点字符(0x00-0x1F)返回非0值,否则返回0

int isspace(int ch) 若ch是空格(' '),水平制表符(''),回车符(''),

走纸换行('\f'),垂直制表符('\v'),换行符('
')

返回非0值,否则返回0

int isupper(int ch) 若ch是大写字母('A'-'Z')返回非0值,否则返回0

int isxdigit(int ch) 若ch是16进制数('0'-'9','A'-'F','a'-'f')返回非0值,

否则返回0

int tolower(int ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z')

int toupper(int ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')



数学函数,所在函数库为math.h、stdlib.h、string.h、float.h

int abs(int i) 返回整型参数i的绝对值

double cabs(struct complex znum) 返回复数znum的绝对值

double fabs(double x) 返回双精度参数x的绝对值

long labs(long n) 返回长整型参数n的绝对值

double exp(double x) 返回指数函数ex的值

double frexp(double value,int *eptr) 返回value=x*2n中x的值,n存贮在eptr中

double ldexp(double value,int exp); 返回value*2exp的值

double log(double x) 返回logex的值

double log10(double x) 返回log10x的值

double pow(double x,double y) 返回xy的值

double pow10(int p) 返回10p的值

double sqrt(double x) 返回+√x的值

double acos(double x) 返回x的反余弦cos-1(x)值,x为弧度

double asin(double x) 返回x的反正弦sin-1(x)值,x为弧度

double atan(double x) 返回x的反正切tan-1(x)值,x为弧度

double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x为弧度

double cos(double x) 返回x的余弦cos(x)值,x为弧度

double sin(double x) 返回x的正弦sin(x)值,x为弧度

double tan(double x) 返回x的正切tan(x)值,x为弧度

double cosh(double x) 返回x的双曲余弦cosh(x)值,x为弧度

double sinh(double x) 返回x的双曲正弦sinh(x)值,x为弧度

double tanh(double x) 返回x的双曲正切tanh(x)值,x为弧度

double hypot(double x,double y) 返回直角三角形斜边的长度(z),

x和y为直角边的长度,z2=x2+y2

double ceil(double x) 返回不小于x的最小整数

double floor(double x) 返回不大于x的最大整数

void srand(unsigned seed) 初始化随机数发生器

int rand() 产生一个随机数并返回这个数

double poly(double x,int n,double c[])从参数产生一个多项式

double modf(double value,double *iptr)将双精度数value分解成尾数和阶

double fmod(double x,double y) 返回x/y的余数

double frexp(double value,int *eptr) 将双精度数value分成尾数和阶

double atof(char *nptr) 将字符串nptr转换成浮点数并返回这个浮点数

double atoi(char *nptr) 将字符串nptr转换成整数并返回这个整数

double atol(char *nptr) 将字符串nptr转换成长整数并返回这个整数

char *ecvt(double value,int ndigit,int *decpt,int *sign)

将浮点数value转换成字符串并返回该字符串

char *fcvt(double value,int ndigit,int *decpt,int *sign)

将浮点数value转换成字符串并返回该字符串

char *gcvt(double value,int ndigit,char *buf)

将数value转换成字符串并存于buf中,并返回buf的指针

char *ultoa(unsigned long value,char *string,int radix)

将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *ltoa(long value,char *string,int radix)

将长整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *itoa(int value,char *string,int radix)

将整数value转换成字符串存入string,radix为转换时所用基数

double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0

int atoi(char *nptr) 将字符串nptr转换成整型数, 并返回这个数,错误返回0

long atol(char *nptr) 将字符串nptr转换成长整型数,并返回这个数,错误返回0

double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数,

long strtol(char *str,char **endptr,int base)将字符串str转换成长整型数,

并返回这个数,

int matherr(struct exception *e)

用户修改数学错误返回信息函数(没有必要使用)

double _matherr(_mexcep why,char *fun,double *arg1p,

double *arg2p,double retval)

用户修改数学错误返回信息函数(没有必要使用)

unsigned int _clear87() 清除浮点状态字并返回原来的浮点状态

void _fpreset() 重新初使化浮点数学程序包

unsigned int _status87() 返回浮点状态字



目录函数,所在函数库为dir.h、dos.h

int chdir(char *path) 使指定的目录path(如:"C:\\WPS")变成当前的工作目录,成

功返回0

int findfirst(char *pathname,struct ffblk *ffblk,int attrib)查找指定的文件,成功

返回0

pathname为指定的目录名和文件名,如"C:\\WPS\\TXT"

ffblk为指定的保存文件信息的一个结构,定义如下:

┏━━━━━━━━━━━━━━━━━━┓

┃struct ffblk ┃

┃{ ┃

┃ char ff_reserved[21]; /*DOS保留字*/┃

┃ char ff_attrib; /*文件属性*/ ┃

┃ int ff_ftime; /*文件时间*/ ┃

┃ int ff_fdate; /*文件日期*/ ┃

┃ long ff_fsize; /*文件长度*/ ┃

┃ char ff_name[13]; /*文件名*/ ┃

┃} ┃

┗━━━━━━━━━━━━━━━━━━┛

attrib为文件属性,由以下字符代表

┏━━━━━━━━━┳━━━━━━━━┓

┃FA_RDONLY 只读文件┃FA_LABEL 卷标号┃

┃FA_HIDDEN 隐藏文件┃FA_DIREC 目录 ┃

┃FA_SYSTEM 系统文件┃FA_ARCH 档案 ┃

┗━━━━━━━━━┻━━━━━━━━┛

例:

struct ffblk ff;

findfirst("*.wps",&ff,FA_RDONLY);



int findnext(struct ffblk *ffblk) 取匹配finddirst的文件,成功返回0

void fumerge(char *path,char *drive,char *dir,char *name,char *ext)

此函数通过盘符drive(C:、A:等),路径dir(\TC、\BC\LIB等),

文件名name(TC、WPS等),扩展名ext(.EXE、.COM等)组成一个文件名

存与path中.

int fnsplit(char *path,char *drive,char *dir,char *name,char *ext)

此函数将文件名path分解成盘符drive(C:、A:等),路径dir(\TC、\BC\LIB等),

文件名name(TC、WPS等),扩展名ext(.EXE、.COM等),并分别存入相应的变量中.

int getcurdir(int drive,char *direc) 此函数返回指定驱动器的当前工作目录名称

drive 指定的驱动器(0=当前,1=A,2=B,3=C等)

direc 保存指定驱动器当前工作路径的变量 成功返回0

char *getcwd(char *buf,iint n) 此函数取当前工作目录并存入buf中,直到n个字

节长为为止.错误返回NULL

int getdisk() 取当前正在使用的驱动器,返回一个整数(0=A,1=B,2=C等)

int setdisk(int drive) 设置要使用的驱动器drive(0=A,1=B,2=C等),

返回可使用驱动器总数

int mkdir(char *pathname) 建立一个新的目录pathname,成功返回0

int rmdir(char *pathname) 删除一个目录pathname,成功返回0

char *mktemp(char *template) 构造一个当前目录上没有的文件名并存于template中

char *searchpath(char *pathname) 利用MSDOS找出文件filename所在路径,

,此函数使用DOS的PATH变量,未找到文件返回NULL



进程函数,所在函数库为stdlib.h、process.h

void abort() 此函数通过调用具有出口代码3的_exit写一个终止信息于stderr,

并异常终止程序。无返回值

int exec…装入和运行其它程序

int execl( char *pathname,char *arg0,char *arg1,…,char *argn,NULL)

int execle( char *pathname,char *arg0,char *arg1,…,

char *argn,NULL,char *envp[])

int execlp( char *pathname,char *arg0,char *arg1,…,NULL)

int execlpe(char *pathname,char *arg0,char *arg1,…,NULL,char *envp[])

int execv( char *pathname,char *argv[])

int execve( char *pathname,char *argv[],char *envp[])

int execvp( char *pathname,char *argv[])

int execvpe(char *pathname,char *argv[],char *envp[])

exec函数族装入并运行程序pathname,并将参数

arg0(arg1,arg2,argv[],envp[])传递给子程序,出错返回-1

在exec函数族中,后缀l、v、p、e添加到exec后,

所指定的函数将具有某种操作能力

有后缀 p时,函数可以利用DOS的PATH变量查找子程序文件。

l时,函数中被传递的参数个数固定。

v时,函数中被传递的参数个数不固定。

e时,函数传递指定参数envp,允许改变子进程的环境,

无后缀e时,子进程使用当前程序的环境。



void _exit(int status)终止当前程序,但不清理现场

void exit(int status) 终止当前程序,关闭所有文件,写缓冲区的输出(等待输出),

并调用任何寄存器的"出口函数",无返回值



int spawn…运行子程序

int spawnl( int mode,char *pathname,char *arg0,char *arg1,…,

char *argn,NULL)

int spawnle( int mode,char *pathname,char *arg0,char *arg1,…,

char *argn,NULL,char *envp[])

int spawnlp( int mode,char *pathname,char *arg0,char *arg1,…,

char *argn,NULL)

int spawnlpe(int mode,char *pathname,char *arg0,char *arg1,…,

char *argn,NULL,char *envp[])

int spawnv( int mode,char *pathname,char *argv[])

int spawnve( int mode,char *pathname,char *argv[],char *envp[])

int spawnvp( int mode,char *pathname,char *argv[])

int spawnvpe(int mode,char *pathname,char *argv[],char *envp[])

spawn函数族在mode模式下运行子程序pathname,并将参数

arg0(arg1,arg2,argv[],envp[])传递给子程序.出错返回-1

mode为运行模式

mode为 P_WAIT 表示在子程序运行完后返回本程序

P_NOWAIT 表示在子程序运行时同时运行本程序(不可用)

P_OVERLAY表示在本程序退出后运行子程序

在spawn函数族中,后缀l、v、p、e添加到spawn后,

所指定的函数将具有某种操作能力

有后缀 p时, 函数利用DOS的PATH查找子程序文件

l时, 函数传递的参数个数固定.

v时, 函数传递的参数个数不固定.

e时, 指定参数envp可以传递给子程序,允许改变子程序运行环境.

当无后缀e时,子程序使用本程序的环境.



int system(char *command) 将MSDOS命令command传递给DOS执行



转换子程序,函数库为math.h、stdlib.h、ctype.h、float.h

char *ecvt(double value,int ndigit,int *decpt,int *sign)

将浮点数value转换成字符串并返回该字符串

char *fcvt(double value,int ndigit,int *decpt,int *sign)

将浮点数value转换成字符串并返回该字符串

char *gcvt(double value,int ndigit,char *buf)

将数value转换成字符串并存于buf中,并返回buf的指针

char *ultoa(unsigned long value,char *string,int radix)

将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *ltoa(long value,char *string,int radix)

将长整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *itoa(int value,char *string,int radix)

将整数value转换成字符串存入string,radix为转换时所用基数

double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0

int atoi(char *nptr) 将字符串nptr转换成整型数, 并返回这个数,错误返回0

long atol(char *nptr) 将字符串nptr转换成长整型数,并返回这个数,错误返回0

double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数,

long strtol(char *str,char **endptr,int base)将字符串str转换成长整型数,

并返回这个数,

int toascii(int c) 返回c相应的ASCII

int tolower(int ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z')

int _tolower(int ch) 返回ch相应的小写字母('a'-'z')

int toupper(int ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')

int _toupper(int ch) 返回ch相应的大写字母('A'-'Z')



诊断函数,所在函数库为assert.h、math.h

void assert(int test) 一个扩展成if语句那样的宏,如果test测试失败,

就显示一个信息并异常终止程序,无返回值

void perror(char *string) 本函数将显示最近一次的错误信息,格式如下:

字符串string:错误信息

char *strerror(char *str) 本函数返回最近一次的错误信息,格式如下:

字符串str:错误信息

int matherr(struct exception *e)

用户修改数学错误返回信息函数(没有必要使用)

double _matherr(_mexcep why,char *fun,double *arg1p,

double *arg2p,double retval)

用户修改数学错误返回信息函数(没有必要使用)



输入输出子程序,函数库为io.h、conio.h、stat.h、dos.h、stdio.h、signal.h

int kbhit() 本函数返回最近所敲的按键

int fgetchar() 从控制台(键盘)读一个字符,显示在屏幕上

int getch() 从控制台(键盘)读一个字符,不显示在屏幕上

int putch() 向控制台(键盘)写一个字符

int getchar() 从控制台(键盘)读一个字符,显示在屏幕上

int putchar() 向控制台(键盘)写一个字符

int getche() 从控制台(键盘)读一个字符,显示在屏幕上

int ungetch(int c) 把字符c退回给控制台(键盘)

char *cgets(char *string) 从控制台(键盘)读入字符串存于string中

int scanf(char *format[,argument…])从控制台读入一个字符串,分别对各个参数进行

赋值,使用BIOS进行输出

int vscanf(char *format,Valist param)从控制台读入一个字符串,分别对各个参数进行

赋值,使用BIOS进行输出,参数从Valist param中取得

int cscanf(char *format[,argument…])从控制台读入一个字符串,分别对各个参数进行

赋值,直接对控制台作操作,比如显示器在显示时字符时即为直接写频方式显示

int sscanf(char *string,char *format[,argument,…])通过字符串string,分别对各个

参数进行赋值

int vsscanf(char *string,char *format,Vlist param)通过字符串string,分别对各个

参数进行赋值,参数从Vlist param中取得

int puts(char *string) 发关一个字符串string给控制台(显示器),

使用BIOS进行输出

void cputs(char *string) 发送一个字符串string给控制台(显示器),

直接对控制台作操作,比如显示器即为直接写频方式显示

int printf(char *format[,argument,…]) 发送格式化字符串输出给控制台(显示器)

使用BIOS进行输出

int vprintf(char *format,Valist param) 发送格式化字符串输出给控制台(显示器)

使用BIOS进行输出,参数从Valist param中取得

int cprintf(char *format[,argument,…]) 发送格式化字符串输出给控制台(显示器),

直接对控制台作操作,比如显示器即为直接写频方式显示

int vcprintf(char *format,Valist param)发送格式化字符串输出给控制台(显示器),

直接对控制台作操作,比如显示器即为直接写频方式显示,

参数从Valist param中取得

int sprintf(char *string,char *format[,argument,…])

将字符串string的内容重新写为格式化后的字符串

int vsprintf(char *string,char *format,Valist param)

将字符串string的内容重新写为格式化后的字符串,参数从Valist param中取得

int rename(char *oldname,char *newname)将文件oldname的名称改为newname

int ioctl(int handle,int cmd[,int *argdx,int argcx])








还有很多 ,由于字数上限了,就发这么多吧!

包含函数:
1函数名称: calloc
函数原型: void * calloc(unsigned n,unsign size);
函数功能: 分配n个数据项的内存连续空间,每个数据项的大小为size
函数返回: 分配内存单元的起始地址,如果不成功,返回0

2函数名称: free
函数原型: void free(void* p);
函数功能: 释放p所指的内存区
函数返回:
参数说明: p-被释放的指针

3函数名称: malloc
函数原型: void * malloc(unsigned size);
函数功能: 分配size字节的存储区
函数返回: 所分配的内存区地址,如果内存不够,返回0

4函数名称: realloc
函数原型: void * realloc(void * p,unsigned size);
函数功能: 将p所指出的已分配内存区的大小改为size,size可以比原来分配的空间大或小
函数返回: 返回指向该内存区的指针.NULL-分配失败

5函数名称: rand
函数原型: int rand(void);
函数功能: 产生0到32767间的随机整数(0到0x7fff之间)
函数返回: 随机整数

6函数名称: abort
函数原型: void abort(void)
函数功能: 异常终止一个进程.

7函数名称: exit
函数原型: void exit(int state)
函数功能: 程序中止执行,返回调用过程
函数返回:
参数说明: state:0-正常中止,非0-非正常中止

8函数名称: getenv
函数原型: char* getenv(const char *name)
函数功能: 返回一个指向环境变量的指针
函数返回: 环境变量的定义
参数说明: name-环境字符串

9函数名称: putenv
函数原型: int putenv(const char *name)
函数功能: 将字符串name增加到DOS环境变量中
函数返回: 0:操作成功,-1:操作失败
参数说明: name-环境字符串

10函数名称: labs
函数原型: long labs(long num)
函数功能: 求长整型参数的绝对值
函数返回: 绝对值

11函数名称: atof
函数原型: double atof(char *str)
函数功能: 将字符串转换成一个双精度数值
函数返回: 转换后的数值
参数说明: str-待转换浮点型数的字符串

12函数名称: atoi
函数原型: int atoi(char *str)
函数功能: 将字符串转换成一个整数值
函数返回: 转换后的数值
参数说明: str-待转换为整型数的字符串

13函数名称: atol
函数原型: long atol(char *str)
函数功能: 将字符串转换成一个长整数
函数返回: 转换后的数值
参数说明: str-待转换为长整型的字符串

14函数名称: ecvt
函数原型: char *ecvt(double value,int ndigit,int *dec,int *sign)
函数功能: 将浮点数转换为字符串
函数返回: 转换后的字符串指针
参数说明: value-待转换底浮点数,ndigit-转换后的字符串长度

15函数名称: fcvt
函数原型: char *fcvt(double value,int ndigit,int *dec,int *sign)
函数功能: 将浮点数变成一个字符串
函数返回: 转换后字符串指针
参数说明: value-待转换底浮点数,ndigit-转换后底字符串长度

该有基本操作基本都有了
希望对你有帮助哈

Status InitStack(Sqstack &S){
//构建一个空栈S
S.base=(SElemType2*)malloc(STACK_INIT_SIZE*sizeof(SElemType2));
if(!S.base) exit(OVERFLOW);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
}//InitStack
Status DestroyStack(Sqstack &S){
//销毁栈S,S不再存在
if(S.base){
free(S.base);
free(S.top);
S.base=S.top=NULL;
}
else cout<<"There is no stack now!"<<endl;
}
Status ClearStack(Sqstack &S){
//把S置为空栈
if(S.base) { S.top=S.base; return OK;}
else cout<<"There is no stack now!"<<endl;
return OK;
}
Status StackEmpty(Sqstack S){
//若S为空栈,则返回TRUE,否则返回FALSE
if(S.base==S.top) return YES;
else return NO;
}
int StackLength(Sqstack S){
//返回S的元素个数,即栈的长度
return S.top-S.base;
}
Status GetTop(Sqstack S,SElemType2 &e){
//若栈不空,则用e返回S的栈顶元素,并返回OK;否则返回ERROR;
if(S.top==S.base) return ERROR;
e=*(S.top-1);
return OK;
}
Status Push(Sqstack &S,SElemType2 e){
//插入元素e为新的栈顶元素
SElemType2 *newbase;
if(S.top-S.base>=S.stacksize){//栈满,追加存储空间
newbase =(SElemType2*)realloc(S.top,(S.stacksize+STACKINCREMENT)*sizeof(SElemType2));
if(!newbase) exit(OVERFLOW);
S.top=newbase;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
}
Status Pop(Sqstack &S,SElemType2 &e){
//若栈不为空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROER
if(S.top==S.base) return ERROR;
e=*--S.top;
return OK;
}
Status visit(Sqstack S){
int i;
for(i=0;i<S.top-S.base;i++)
cout<<S.base[i]<<" ";
if(i==S.top-S.base) return YES;
return NO;
}
Status StackTraverse(Sqstack S,Status(*visit)(Sqstack)){
//从栈顶到栈底依次对栈中每个元素调用函数visit()。一旦visit()失败,则操作失败
if((visit)(S)) return YES;
else return NO;
}
链栈存储定义头文件:
typedef char SElemType;
typedef struct LNode{
SElemType data;
struct LNode *next;
}LNode,*StackPtr;
typedef struct{
StackPtr base;
StackPtr top;
}Linkstack;
链栈基本操作定义头文件:
Status Initstack(Linkstack &S){
//创建一个空的链栈,S作为栈底
//int i;
S.base=S.top=(StackPtr)malloc(sizeof(LNode));
if(!S.base) exit(OVERFLOW);
S.base->next=NULL;
return OK;
//if(n) cout<<"Please enter the initial elements in the stack!"<<endl;
//for(i=1;i<=n;i++){
// p=(Linkstack)malloc(sizeof(Lstack));
// cout<<"The number "<<i<<" element:";
// cin>>p->data;
// S->next=p;p->next=NULL;
// top=p;
// }
}
Status Destroystack_L(Linkstack S){
StackPtr p=NULL;
if(!S.base) return OK;
else{
for(p=S.base;p!=S.top;p=p->next)
free(p);
free(S.top);
return OK;
}
}
Status GetTop(Linkstack S,SElemType &e){
if(S.base==S.top) return ERROR;
else
e=S.top->data;
return OK;
}
Status Empty(Linkstack S){
//判断栈是否为空
// Linkstack base,top;
if(S.base==S.top) return YES;//cout<<"The stack is empty";
else return NO;
}
int Length(Linkstack S){
StackPtr p;
int i;
if(S.base==S.top) return 0;
for(p=S.base,i=0;p->next!=NULL;++i)
p=p->next;
return i;
}
Status Push(Linkstack &S,SElemType e){
//进栈,向栈中压入元素'e'
//压入后,栈的栈底指针S.base所指向的那个结点是空结点,其data域中没存有数据
// Linkstack newnode,top;
StackPtr newbase;
newbase=(StackPtr)malloc(sizeof(LNode));
if(!newbase) exit(OVERFLOW);
newbase->data=e;
newbase->next=NULL;
S.top->next=newbase;
S.top=newbase;//修改栈顶指针,将当前栈顶指针改为指向新插入的结点
//测试栈顶指针是否按要求改变:cout<<S.base<<" "<<S.top<<endl;
return OK;
}
Status Pop(Linkstack &S,SElemType &e){
//出栈,并且用'e'带出栈顶元素
// Linkstack top,base;
StackPtr p;
if(S.base==S.top) return ERROR;
e=S.top->data;
for(p=S.base;p->next!=S.top;)
p=p->next; //修改栈顶指针:找寻原始栈顶的前一个结点,将其变成弹出原来栈顶后的新栈顶
free(S.top);
S.top=p;
S.top->next=NULL;
//测试栈顶指针是否按要求改变:cout<<S.base<<" "<<S.top<<endl;
return OK;
}
Status visit(Linkstack S){
StackPtr p;
if(S.base==S.top) return ERROR;
else{
for(p=S.base;p->next!=NULL;){
p=p->next;
cout<<p->data<<" ";
}
return OK;
}
}
Status Traverse(Linkstack S,Status (*visit)(Linkstack)){
if(visit(S)) return YES;
else return NO;
}
顺序栈主调函数:
#include"comdef.h"
#include"Sqstackdef.h"
#include"Sqstackapp.h"
int main(){
Sqstack S;
S.base=NULL;
int choice,len;
SElemType e;
cout<<"Choice menu:"<<endl;
cout<<"'1':To create an empty stack!"<<endl;
cout<<"'2':To destroy the stack!"<<endl;
cout<<"'3':To clear the stack!"<<endl;
cout<<"'4':To judge if the stack is empty!"<<endl;
cout<<"'5':To get the length of the stack!"<<endl;
cout<<"'6':To get the top element in the stack!"<<endl;
cout<<"'7':To push 'e' into the stack!"<<endl;
cout<<"'8':To pop the top element in the stack!"<<endl;
cout<<"'9':To travel the stack!"<<endl;
cout<<"Please input your choice:(0 to end)";
cin>>choice;
while(choice){
switch(choice) {
case 1:
if(InitiStack(S))
cout<<"You have created an empty stack successfully!"<<endl<<"You can choose '7' to push an element into it!"<<endl;
break;
case 2:
if(!S.base){
cout<<"There is no stack now!So you can't choose this operate now!"<<endl;
break;
}
DestroyStack(S);
cout<<"You have destroyed the stack successfully!"<<endl;
break;
case 3:
if(!S.base){
cout<<"There is no stack now!So you can't choose this operate now!"<<endl;
break;
}
ClearStack(S);
cout<<"You have cleared the stack successfully!"<<endl;
break;
case 4:
if(!S.base){
cout<<"There is no stack now!So you can't choose this operate now!"<<endl;
break;
}
if(StackEmpty(S)) cout<<"The stack is empty now!"<<endl;
else cout<<"The stack isn't empty!"<<endl;
break;
case 5:
if(!S.base){
cout<<"There is no stack now!So you can't choose this operate now!"<<endl;
break;
}
else len=StackLength(S);
cout<<"The length is:"<<len<<endl;
break;
case 6:
if(!S.base){
cout<<"There is no stack now!So you can't choose this operate now!"<<endl;
break;
}
if(GetTop(S,e))
cout<<"The top element is:"<<e<<endl;
else cout<<"The stack is empty now!"<<endl;
break;
case 7:
if(!S.base){
cout<<"There is no stack now!So you can't choose this operate now!"<<endl;
break;
}
cout<<"Please input the element you want to push into the stack:";
cin>>e;
Push(S,e);
cout<<"You have pushed "<<e<<" at the top of the stack successfully!"<<endl;
break;
case 8:
if(!S.base){
cout<<"There is no stack now!So you can't choose this operate now!"<<endl;
break;
}
if(Pop(S,e)){
cout<<"Present top element is:"<<e<<endl;
cout<<"You have poped the top element successfully!"<<endl;
}
else cout<<"The stack is empty now!"<<endl;
break;
case 9:
if(!S.base){
cout<<"There is no stack now!So you can't choose this operate now!"<<endl;
break;
}
if(S.base==S.top) cout<<"The stack is empty now!";
else cout<<"Present stack is:";
StackTraverse(S,visit);
cout<<endl;
break;
}
cout<<"Please input your choice:(0 to end)";
cin>>choice;
}
system("PAUSE");
return 0;
}
链栈主调函数:
#include"comdef.h"
#include"Lstackdef.h"
#include"Lstackapp.h"
int main(){
Linkstack S;
S.base=S.top=NULL;
int choice;
SElemType e;
cout<<"Choice menu:"<<endl;
cout<<"'1':To create an empty stack!"<<endl;
cout<<"'2':To judge if the stack is empty!"<<endl;
cout<<"'3':To get the length of the present stack!"<<endl;
cout<<"'4':To push an element at the top of the stack!"<<endl;
cout<<"'5':To pop the element at the top of the stack!"<<endl;
cout<<"'6':To travel the stack!"<<endl;
cout<<"Please enter your choice:(0 to end)";
cin>>choice;
while(choice){
switch(choice){
case 1:
if(Initistack(S))
cout<<"You have created an empty stack successfully!"<<endl;
break;
case 2:
if(!S.base){
cout<<"There is no stack now!You can't choose this operate at the moment!"<<endl<<"You can choose '1' to created one!"<<endl;
break;
}
if(Empty(S)) cout<<"The stack is empty now!"<<endl;
else cout<<"The stack isn't empty now!"<<endl;
break;
case 3:
if(!S.base){
cout<<"There is no stack now!You can't choose this operate at the moment!"<<endl<<"You can choose '1' to created one!"<<endl;
break;
}
//测试栈顶与栈底指针是否按要求发生了改变:cout<<S.base<<" "<<S.top<<endl;
cout<<"The length of the stack is:"<<Length(S)<<endl;
break;
case 4:
if(!S.base){
cout<<"There is no stack now!You can't choose this operate at the moment!"<<endl;
break;
}
cout<<"Please enter the element that you want to push into the stack:";
cin>>e;
if(Push(S,e)) cout<<"You have push the element:"<<e<<" onto the top of the stack successfully!"<<endl;
else cout<<"Sorry!You have failed to push "<<e<<" onto the top of the stack!"<<endl;
break;
case 5:
if(!S.base){
cout<<"There is no stack now!You can't choose this operate at the moment!"<<endl;
break;
}
if(Pop(S,e)) cout<<"You have poped the top element:"<<e<<" successfully!"<<endl;
else cout<<"Sorry!The stack is empty now!So there isn't any element for you to pop!"<<endl;
break;
case 6:
if(!S.base){
cout<<"There is no stack now!You can't choose this operate at the moment!"<<endl;
break;
}
if(Empty(S)){
cout<<"The stack is empty now!"<<endl;
break;
}
cout<<"Present stack is:";
Traverse(S,visit);
cout<<endl;
break;
}
cout<<"Please enter your choice:(0 to end)";
cin>>choice;
}
system("PAUSE");
return 0;
}

十万火急 和一个喜欢的女孩 表白后 她给了个 流汗的表情 后来又发了一...
十万火急 和一个喜欢的女孩 表白后 她给了个 流汗的表情 后来又发了一张脚踢人的表情。  我来答 1个回答 #热议# 鹤岗爆火背后的原因是什么?浮云492131 2010-10-04 · TA获得超过410个赞 知道小有建树答主 回答量:112 采纳率:100% 帮助的人:26.3万 我也去答题访问个人页 关注 展开全部...

教育的奖励与惩罚的区别和联系 在线等 十万火急!!
强化法是以操作性条件反应原理为基础的,即一个行为发生后,如果紧跟着一个强化刺激,这个行为就会再次发生。强化有两种,一种是在所期待的行为出现后,给予一个愉快刺激(如糖果、表扬、奖品),这叫正强化;二是在所期待的行为出现后,撤销一个厌恶刺激(如不许看电视、指责等),这叫负强化。这两种...

十万火急等待您的帮助!
好像是木马程序,进入安全模式用杀毒软件或者360卫士全盘扫描一下。如果不行格式化系统盘,重新安装系统也不麻烦的

急救啊!!!电脑蓝屏问题,十万火急
电脑蓝屏怎么办

我妈在的了流感时晚上总好左半边头疼,并且发低烧、出汗,这是为什么...
你好,你妈妈是得了流感后引起的血管神经性头痛。疼痛的部位多在太阳穴部位,伴有血管的搏动(问问是不是这样?)治疗:首先要服用消炎药和感冒药,如:头孢克肟、新康泰克、中联强效片等。如果头痛厉害,可以加用:芬必得、扶他林、颅痛定等对症治疗药。还可以用中成药:如正天丸、天麻丸等。配合局部热敷...

初二数学题呀!在线等!在线等!十万火急!急急急急急急急急急急急急急急...
1、思路:在△AEF中,欲证AD垂直平分EF,即证明。△AEF为等腰△,即AE=AF。证明:在△ABC中 ∵AD平分∠BAC ∴∠BAD=∠DAC 又,∠DEA=∠DFA=90°,AD为△AED和△AFD的公共边 因此,RT△AED≌RT△AFD 由此可得,AE=AF 即 ,△AEF为等腰△ 在等腰△AEF中 ∵AD为∠EAF的平分线 则,AD...

拍的题急急急十万火急求大神帮忙在线等
live I 是主语 goes my father是主语,第三人称单数 driving like+动词ing doesn't like 第三人称单数的否定形式 is traffic 是不可数名词 His is will work next year是将来时的标志 read can+动词原形 后面都是 listen come cook 上面这些题都是考查一般现在时的用法,特别是第三...

打印机共享~十万火急
在Windows XP中默认安装了TCP\/IP。但是,如果出了网络问题想卸载后重新安装TCP\/IP就不容易了:在“本地连接”属性中显示的此连接使用下列项目列表中单击Internet协议(TCP\/IP)项,您将发现卸载按钮不可用(被禁用)。这是因为传输控制协议\/Internet协议(TCP\/IP)堆栈是Microsoft XP\/ 2003的核心组件,不能...

万分火急!!请半个月假什么理由最好
2、俗套肥皂剧理由:飞机延误了,火车晚点了,家里遭窃了。成功率50%,技术0%。为了请假这样的小事,犯不着剧情大逆转吧。3、最常见的理由:去外地看望父母,或者父母来看望需陪同。主打亲情牌,采用声泪俱下的煽情说明父母老迈,希望抽时间陪他们。成功率80%,技术80%。不过只适合家在异地人士。4、...

十万火急!下列化学题怎么做?在线等!
1.航天飞机材料,炊具等 2.1000kg*112\/160=700kg 3.(1)沙漠地区气候干燥,空气中的水分少 (2)隔绝水与铁接触 4.ZnCO3+2C=(高温)=Zn+3CO Cu2O+C=(高温)=2Cu+CO

相关链接2

返回顶部
凡事房车自主流
凡事网