C语言 栈的使用

合集下载

栈的实验报告结论(3篇)

栈的实验报告结论(3篇)

第1篇一、实验目的1. 理解栈的基本概念和操作;2. 掌握栈的顺序存储和链式存储实现方法;3. 熟悉栈在程序设计中的应用。

二、实验内容1. 栈的顺序存储结构实现;2. 栈的链式存储结构实现;3. 栈的基本操作(入栈、出栈、判空、求栈顶元素);4. 栈在程序设计中的应用。

三、实验方法1. 采用C语言进行编程实现;2. 对实验内容进行逐步分析,编写相应的函数和程序代码;3. 通过运行程序验证实验结果。

四、实验步骤1. 实现栈的顺序存储结构;(1)定义栈的结构体;(2)编写初始化栈的函数;(3)编写入栈、出栈、判空、求栈顶元素的函数;(4)编写测试程序,验证顺序存储结构的栈操作。

2. 实现栈的链式存储结构;(1)定义栈的节点结构体;(2)编写初始化栈的函数;(3)编写入栈、出栈、判空、求栈顶元素的函数;(4)编写测试程序,验证链式存储结构的栈操作。

3. 栈在程序设计中的应用;(1)实现一个简单的四则运算器,使用栈进行运算符和操作数的存储;(2)实现一个逆序输出字符串的程序,使用栈进行字符的存储和输出;(3)编写测试程序,验证栈在程序设计中的应用。

五、实验结果与分析1. 顺序存储结构的栈操作实验结果:(1)入栈操作:在栈未满的情况下,入栈操作成功,栈顶元素增加;(2)出栈操作:在栈非空的情况下,出栈操作成功,栈顶元素减少;(3)判空操作:栈为空时,判空操作返回真,栈非空时返回假;(4)求栈顶元素操作:在栈非空的情况下,成功获取栈顶元素。

2. 链式存储结构的栈操作实验结果:(1)入栈操作:在栈未满的情况下,入栈操作成功,链表头指针指向新节点;(2)出栈操作:在栈非空的情况下,出栈操作成功,链表头指针指向下一个节点;(3)判空操作:栈为空时,判空操作返回真,栈非空时返回假;(4)求栈顶元素操作:在栈非空的情况下,成功获取栈顶元素。

3. 栈在程序设计中的应用实验结果:(1)四则运算器:成功实现加、减、乘、除运算,并输出结果;(2)逆序输出字符串:成功将字符串逆序输出;(3)测试程序:验证了栈在程序设计中的应用。

C语言【栈的应用数制转换】

C语言【栈的应用数制转换】

C语⾔【栈的应⽤数制转换】1 #include <stdio.h>2 #include <malloc.h>3 #include <process.h>4#define OK 15#define STACK_INIT_SIZE 56#define STACKINCREMENT 57 typedef int ElemType;89 typedef struct10 {1112 ElemType *base;13 ElemType *top;14int stacksize;15 }SqStack;16void InitStack(SqStack *S)17 {18 S->base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType)); //分配内存19if(!S->base) //如果为空,则退出20 exit(1);21 S->top=S->base;22 S->stacksize=STACK_INIT_SIZE;23 }24int push(SqStack *S,ElemType e)/*顺序⼊栈*/25 {26if(S->top-S->base>S->stacksize)//栈中的数据长度⼤于给定分配⼤⼩27 {28 S->base=(ElemType *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(ElemType));//增加内存⼤⼩29if(!S->base)30 exit(1);31 S->top=S->base+S->stacksize;//将增加的长度给更新32 S->stacksize+=STACKINCREMENT;//更新增加后的长度33 }34 *S->top=e;35 S->top++;36return1;3738 }39 ElemType pop(SqStack *S,ElemType *e)/*顺序出栈*/40 {41if(S->top==S->base) //出栈判断栈是否是空42 printf("此时栈为空,不能出栈!\n");43 *e=*--S->top;44return *e;45 }46int StackEmpty(SqStack *S)/*判断顺序栈是否为空*/47 {48if(S->top==S->base)49return1;50else51return0;5253 }54void DestroyStack(SqStack *S)/*顺序栈销毁*/55 {56 free(S->top);57 }5859void Conversion()/*数值转换*/60 {61int n;62int m;63 SqStack s;64 ElemType e;65 InitStack(&s);66 printf("请输⼊带转换的数值:\n");67 scanf("%d",&n);68 printf("请输⼊要转化的数制:\n");69 scanf("%d",&m);70while(n)71 {72 push(&s,n%m);73 n=n/m;74 }75while(!StackEmpty(&s))76 {77 pop(&s,&e);78 printf("%d",e);7981 printf("\n");82 DestroyStack(&s);8384 }85int main(void) /*程序⼊⼝*/86 {87 Conversion();88return OK;89 }1 #include <stdio.h>2 #include <malloc.h>3 #include <process.h>4#define OK 15#define STACK_INIT_SIZE 56#define STACKINCREMENT 57 typedef int ElemType;89 typedef struct10 {1112 ElemType *base;13 ElemType *top;14int stacksize;15 }SqStack;16void InitStack(SqStack *S)17 {18 S->base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType)); //分配内存19if(!S->base) //如果为空,则退出20 exit(1);21 S->top=S->base;22 S->stacksize=STACK_INIT_SIZE;23 }24int push(SqStack *S,ElemType e)/*顺序⼊栈*/25 {26if(S->top-S->base>S->stacksize)//栈中的数据长度⼤于给定分配⼤⼩27 {28 S->base=(ElemType *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(ElemType));//增加内存⼤⼩29if(!S->base)30 exit(1);31 S->top=S->base+S->stacksize;//将增加的长度给更新32 S->stacksize+=STACKINCREMENT;//更新增加后的长度33 }34 *S->top=e;35 S->top++;36return1;3738 }39 ElemType pop(SqStack *S,ElemType *e)/*顺序出栈*/40 {41if(S->top==S->base) //出栈判断栈是否是空42 printf("此时栈为空,不能出栈!\n");43 *e=*--S->top;44return *e;45 }46int StackEmpty(SqStack *S)/*判断顺序栈是否为空*/47 {48if(S->top==S->base)49return1;50else51return0;5253 }54void DestroyStack(SqStack *S)/*顺序栈销毁*/55 {56 free(S->top);57 }5859void Conversion()/*数值转换*/60 {61int n;62int m;63 SqStack s;64 ElemType e;65 InitStack(&s);66 printf("请输⼊带转换的数值:\n");67 scanf("%d",&n);68 printf("请输⼊要转化的数制:\n");69 scanf("%d",&m);70while(n)71 {72 push(&s,n%m);73 n=n/m;75while(!StackEmpty(&s))76 {77 pop(&s,&e);78 printf("%d",e);7980 }81 printf("\n");82 DestroyStack(&s);8384 }85int main(void) /*程序⼊⼝*/86 {87 Conversion();88return OK;89 }。

c语言 回文数 栈

c语言 回文数 栈

c语言回文数栈回文数是指正读和反读都相同的整数。

例如,121、12321都是回文数。

在计算机科学中,我们可以使用栈来判断一个数是否为回文数。

我们需要明确一点:回文数是十进制下的概念,而计算机中的数是以二进制表示的。

因此,在计算机中判断一个数是否为回文数,我们需要先将其转换为字符串。

接下来,我们可以使用栈来进行判断。

栈是一种先进后出的数据结构,我们可以利用栈的特性来判断字符串是否为回文。

具体的算法如下:1. 将整数转换为字符串。

2. 创建一个空栈。

3. 将字符串的每个字符依次入栈。

4. 将栈中的字符出栈,并与字符串中的字符逐个比较。

5. 如果所有字符都相同,则该字符串是回文数;否则,不是回文数。

下面我们用C语言来实现这个算法:```c#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_SIZE 100typedef struct {char data[MAX_SIZE];int top;} Stack;// 初始化栈void initStack(Stack *s) {s->top = -1;}// 入栈void push(Stack *s, char c) { s->data[++(s->top)] = c;}// 出栈char pop(Stack *s) {return s->data[(s->top)--]; }// 判断回文数int isPalindrome(int num) {char str[MAX_SIZE];sprintf(str, "%d", num); // 将整数转换为字符串 int len = strlen(str);Stack s;initStack(&s);// 将字符串的每个字符入栈for (int i = 0; i < len; i++) {push(&s, str[i]);}// 将栈中的字符和字符串中的字符逐个比较for (int i = 0; i < len; i++) {if (pop(&s) != str[i]) {return 0; // 不是回文数}}return 1; // 是回文数}int main() {int num;printf("请输入一个整数:");scanf("%d", &num);if (isPalindrome(num)) {printf("%d是回文数。

c语言栈内存的申请

c语言栈内存的申请

c语言栈内存的申请C语言中,栈内存的申请是一个非常重要的话题。

栈是一种用于存储局部变量和函数调用信息的内存区域,它的大小在程序编译时就已经确定。

在C语言中,可以使用栈内存来存储一些临时变量和函数的返回地址。

在C语言中,可以使用关键字`alloca`或者`_alloca`来在栈上动态分配内存。

这种方式类似于`malloc`函数在堆上动态分配内存,但是它在函数返回时会自动释放分配的内存,不需要手动调用`free`函数来释放内存。

下面是一个简单的示例,演示了如何在C语言中使用`alloca`函数在栈上动态分配内存:c.#include <stdio.h>。

#include <alloca.h>。

int main() {。

int n = 10;int arr = (int)alloca(n sizeof(int)); for (int i = 0; i < n; i++) {。

arr[i] = i i;}。

for (int i = 0; i < n; i++) {。

printf("%d ", arr[i]);}。

return 0;}。

在这个示例中,我们使用`alloca`函数动态分配了一个包含10个整数的数组,并且在程序结束时会自动释放这部分内存。

需要注意的是,栈内存的空间是有限的,因此在申请栈内存时要格外小心。

如果申请的内存过大,可能会导致栈溢出的问题,因此需要谨慎使用栈内存的动态分配。

总之,栈内存的申请是C语言编程中一个重要的技术,合理地利用栈内存可以提高程序的效率和性能。

但是需要注意栈内存的大小是有限的,需要谨慎使用动态分配栈内存的方式。

c语言栈计算表达式

c语言栈计算表达式

c语言栈计算表达式在计算机科学中,栈是一种非常重要的数据结构,被广泛应用于编译器、操作系统、网络通信等领域。

在本文中,我们将探讨如何使用C语言实现栈来计算表达式。

表达式是由操作数、操作符和括号组成的数学式子,例如:3 + 4 * 2 / (1 - 5)。

在计算表达式时,我们需要遵循一定的计算规则,如乘除法优先于加减法,括号内的计算优先于括号外的计算等。

我们可以使用栈来实现对表达式的计算。

具体步骤如下:1. 定义两个栈:一个操作数栈和一个操作符栈。

2. 从左到右遍历表达式的每一个字符,如果是数字则将其压入操作数栈;如果是操作符则将其压入操作符栈,并根据运算规则进行计算。

3. 在遍历完成后,操作符栈中可能还有未计算的操作符,需要继续计算,直到操作符栈为空。

4. 最终操作数栈中只剩下一个数,即为表达式的计算结果。

下面是一段示例代码,用于计算简单的表达式:```#include <stdio.h>#include <stdlib.h>#include <ctype.h>#define MAX_SIZE 100typedef struct {int data[MAX_SIZE];int top;} Stack;void initStack(Stack *s) {s->top = -1;}void push(Stack *s, int item) { if (s->top == MAX_SIZE - 1) { printf('Stack Overflow');exit(1);}s->data[++s->top] = item;}int pop(Stack *s) {if (s->top == -1) {printf('Stack Underflow');exit(1);}return s->data[s->top--];}int isEmpty(Stack *s) {return s->top == -1;}int isFull(Stack *s) {return s->top == MAX_SIZE - 1;}int peek(Stack *s) {return s->data[s->top];}int evaluate(char *expr) {Stack operandStack, operatorStack; initStack(&operandStack);initStack(&operatorStack);int i = 0;while (expr[i] != '0') {if (isdigit(expr[i])) {int num = 0;while (isdigit(expr[i])) {num = num * 10 + (expr[i] - '0'); i++;}push(&operandStack, num);}else if (expr[i] == '(') {push(&operatorStack, expr[i]);i++;}else if (expr[i] == ')') {while (!isEmpty(&operatorStack) && peek(&operatorStack) != '(') {int op2 = pop(&operandStack);int op1 = pop(&operandStack);char op = pop(&operatorStack);int result;switch (op) {case '+':result = op1 + op2;break;case '-':result = op1 - op2;break;case '*':result = op1 * op2;break;case '/':result = op1 / op2;break;}push(&operandStack, result);}pop(&operatorStack);i++;}else if (expr[i] == '+' || expr[i] == '-' || expr[i] == '*' || expr[i] == '/') {while (!isEmpty(&operatorStack) &&peek(&operatorStack) != '(' &&((expr[i] == '*' || expr[i] == '/') || (expr[i] == '+' || expr[i] == '-') &&(peek(&operatorStack) == '*' || peek(&operatorStack) == '/'))) {int op2 = pop(&operandStack);int op1 = pop(&operandStack);char op = pop(&operatorStack);int result;switch (op) {case '+':result = op1 + op2;break;case '-':result = op1 - op2;break;case '*':result = op1 * op2;break;case '/':result = op1 / op2;break;}push(&operandStack, result); }push(&operatorStack, expr[i]); i++;}else {i++;}}while (!isEmpty(&operatorStack)) { int op2 = pop(&operandStack);int op1 = pop(&operandStack);char op = pop(&operatorStack);int result;switch (op) {case '+':result = op1 + op2;break;case '-':result = op1 - op2;break;case '*':result = op1 * op2;break;case '/':result = op1 / op2;break;}push(&operandStack, result);}return pop(&operandStack);}int main() {char expr[MAX_SIZE];printf('Enter an expression: ');fgets(expr, MAX_SIZE, stdin);int result = evaluate(expr);printf('Result = %d', result);return 0;}```在这段代码中,我们定义了一个栈结构体,包含了栈的数据和栈顶指针。

c栈的用法

c栈的用法

c栈的用法
在C语言中,栈(Stack)是一种特殊的线性表,只允许在表的一端进行插入和删除操作,通常被称为"后进先出"(LIFO)或"先进后出"(FILO)线性表。

以下是C语言中使用栈的基本步骤:
首先,需要定义一个栈的数据结构,通常使用动态内存分配函数malloc()来为栈分配内存空间。

栈通常包含一个指向栈顶元素的指针top,以及一个指向栈底的指针bottom。

1. 进栈(Push):当元素进栈时,需要将元素存储在栈顶指针所指向的位置,并将栈顶指针向上移动一个存储单元。

2. 出栈(Pop):当需要使用栈顶元素时,需要将栈顶指针向下移动一个存储单元,并返回栈顶元素。

C语言实现堆栈(自己的)

C语⾔实现堆栈(⾃⼰的)stack.h#ifndef __STACK_H__#define __STACK_H__#include <stdio.h>#include <stdlib.h>#include <stdbool.h>typedef int ElementType;struct SNode {ElementType *Data; /* 存储元素的数组 */int Top; /* 栈顶指针 */int MaxSize; /* 堆栈最⼤容量 */};typedef struct SNode *Stack;Stack CreateStack( int MaxSize ); //建⽴结构体堆栈bool IsFull( Stack S ); //判断堆栈是是否溢出bool Push( Stack S, ElementType X ); //压栈bool IsEmpty( Stack S ); //判断堆栈是是否为空ElementType Pop( Stack S ); //出栈#endifstack.c#include "stack.h"#include "sys.h"u8 Choose_Stack_Flag=0; //未检测到加减符号时候,0:⼀个结构体,检测到1:另⼀个结构体Stack CreateStack( int MaxSize ){Stack S = (Stack)malloc(sizeof(struct SNode));S->Data = (ElementType *)malloc(MaxSize * sizeof(ElementType));S->Top = -1;S->MaxSize = MaxSize;return S;}bool IsFull( Stack S ){return (S->Top == S->MaxSize-1);}bool Push( Stack S, ElementType X ){if ( IsFull(S) ) {printf("堆栈满");return false;}else {S->Data[++(S->Top)] = X;return true;}}bool IsEmpty( Stack S ){return (S->Top == -1);}ElementType Pop( Stack S ){if ( IsEmpty(S) ) {printf("堆栈空");return ERROR; /* ERROR是ElementType的特殊值,标志错误 ERROR 0 */}elsereturn ( S->Data[(S->Top)--] );}。

c语言栈内存的申请

c语言栈内存的申请
C语言中的栈内存是一种用于存储局部变量和函数调用信息的内存区域。

在C语言中,栈内存的申请和释放是由编译器自动完成的,无需程序员手动管理。

当一个函数被调用时,编译器会在栈内存中为该函数分配一块内存空间,用于存储函数的局部变量、函数参数、返回地址等信息。

当函数执行完毕后,这块内存空间会被自动释放,以便其他函数使用。

在C语言中,栈内存的申请和释放是由编译器自动完成的,程序员无需关心具体的内存管理细节。

这种自动管理的方式使得编程更加方便和安全,避免了内存泄漏和内存溢出等问题。

然而,栈内存的大小是有限的,一般情况下只有几兆字节的大小。

因此,如果在函数中申请过多的局部变量或者使用递归调用等方式导致栈内存空间不足,就会发生栈溢出的错误。

为了避免这种情况的发生,程序员需要合理地设计函数和变量的使用,避免占用过多的栈内存空间。

总之,C语言中的栈内存是一种自动管理的内存区域,用于存储函数调用信息和局部变量。

程序员无需手动管理栈内存,但需要
注意避免栈溢出的问题。

通过合理设计函数和变量的使用,可以更好地利用栈内存的有限空间,确保程序的正常运行。

用栈检验括号匹配c语言

用栈检验括号匹配c语言一、背景介绍在程序设计中,括号匹配是一个非常重要的问题。

在C语言中,括号匹配错误往往会导致程序崩溃或者出现不可预料的结果。

因此,在编写C语言代码时,检验括号匹配是必不可少的。

二、栈的概念栈是一种数据结构,它具有后进先出(LIFO)的特点。

通俗地说,就像我们平时吃饭时叠放餐具一样,后放进去的餐具会先被取出来。

三、栈的实现在C语言中,可以使用数组和指针来实现栈。

以下是使用数组实现栈的代码:```#define MAXSIZE 100 // 定义栈的最大长度typedef struct {char data[MAXSIZE]; // 存储数据int top; // 栈顶指针} Stack;void initStack(Stack *s) {s->top = -1;}int isStackEmpty(Stack *s) {return s->top == -1;}int isStackFull(Stack *s) {return s->top == MAXSIZE - 1; }void push(Stack *s, char c) {if (isStackFull(s)) {printf("Stack is full.\n");return;}s->data[++(s->top)] = c;}char pop(Stack *s) {if (isStackEmpty(s)) {printf("Stack is empty.\n");return '\0';}return s->data[(s->top)--];}```四、括号匹配的思路在C语言中,括号包括圆括号"()"、方括号"[]"和花括号"{}"。

检验括号匹配的思路如下:1. 遍历字符串中的每一个字符。

c语言堆栈和队列函数大全

C语言堆栈和队列函数大全一.顺序栈1.宏定义#include<stdio.h>#include<stdlib.h>#define MAXSIZE ****#define datatype ****2.结构体typedef struct{datatype data[MAXSIZE];int top;}Seqstack;3.基本函数Seqstack *Init_Seqstack()/*置空栈函数(初始化)1.先决条件:无;2.函数作用:首先建立栈空间,然后初始化栈顶指针,返回栈s的地址*/{Seqstack *s;s=(Seqstack *)malloc(sizeof(Seqstack));s->top=-1;return s;}int Empty_Seqstack(Seqstack *s) /*判栈空函数1.先决条件:初始化顺序栈;2.函数作用:判断栈是否为空,空返回1,不空返回0*/ {if(s->top==-1) return 1;else return 0;}int Push_Seqstack(Seqstack *s,datatype x) /*入栈函数1.先决条件:初始化顺序栈2.函数作用:将数据x入栈,栈满则不能,成功返回1,因栈满失败返回0*/ {if(s->top==MAXSIZE-1)return 0;s->top=s->top+1;s->data[s->top]=x;return 1;}int Pop_Seqstack(Seqstack *s,datatype *x) acidity, mL.; M--calibration of the molar concentration of sodium hydroxide standard solution, moI/L; V--amount of the volume of sodium hydroxide standard solution, Ml; M--the weight of the sample, g. Such as poor meets the requirements, take the arithmetic mean of the second determination as a result. Results one decimal. 6, allowing differential analyst simultaneously or in quick succession for the second determination, the absolute value of the difference of the results. This value should be no more than 1.0. 1, definitions and principles for determination of ash in starches, starch and ash: starch samples of ash the residue obtainedafter weight. Original sample residue weight of sample weight or weight expressed as a percentage of the dry weight of the sample. Samples ofash at 900 ? high temperature until ashing sample ... The Crucible: determination of Platinum or other conditions of the affected material, capacity of 50mL. Dryer: has effectively adequate drying agent and-perforated metal plate or porcelain. Ashing furnaces: device for controlling and regulating temperature, offers 900 incineration temperature of 25 c. Analytical balance. Electric hot plate or Bunsen. 3, crucible of analysis steps preparation: Crucible must first wash with boiling dilute hydrochloric acid, then wash with a lot of water and then rinse with distilled water. Wash the Crucible within ashing furnace, heated at 900 to 25 ? 30min, and in the desiccator to cool to room temperature and then weighing,/*出栈函数1.先决条件:初始化顺序栈2.函数作用:从栈中出一个数据,并将其存放到x中,成功返回1,因栈空失败返回0*/{if(s->top==-1)return 0;*x=s->data[s->top];s->top--;return 1;}int Top_Seqstack(Seqstack *s,datatype *x)/*取栈顶元素函数1.先决条件:初始化顺序栈2.函数作用:取栈顶元素,并把其存放到x中,成功返回1,因栈空失败返回0*/{if(s->top==-1)return 0;*x=s->data[s->top];return 1;}int Printf_Seqstack(Seqstack *s) /*遍历顺序栈函数1.先决条件:初始化顺序栈2.函数作用:遍历顺序栈,成功返回1*/ {int i,j=0;for(i=s->top;i>=0;i--){printf("%d ",s->data[i]);/*因datatype不同而不同*/j++;if(j%10==0)printf("\n");}printf("\n");return 1;}int Conversation_Seqstack(int N,int r) /*数制转换函数(顺序栈)1.先决条件:具有置空栈,入栈,出栈函数2.函数作用:将N转换为r进制的数*/{Seqstack *s;datatype x;printf("%d转为%d进制的数为:",N,r);/*以后可以删除去*/s=Init_Seqstack();do{Push_Seqstack(s,N%r);N=N/r;acidity, mL.; M--calibration of the molar concentration of sodium hydroxide standard solution, moI/L; V--amount of the volume of sodium hydroxide standard solution, Ml; M--the weight of the sample, g. Such as poor meets the requirements, take the arithmetic mean of the second determination as a result. Results one decimal. 6, allowing differential analyst simultaneously or in quick succession for the second determination, the absolute value of the difference of the results. This value should be no more than 1.0. 1, definitions and principles for determination of ash in starches, starch and ash: starch samples of ash the residue obtained after weight. Original sample residue weight of sample weight or weight expressed as a percentage of the dry weight of the sample. Samples of ash at 900 ? high temperature until ashing sample ... The Crucible: determination of Platinum or other conditions of the affected material, capacity of 50mL. Dryer: has effectivelyadequate drying agent and-perforated metal plate or porcelain. Ashing furnaces: device for controlling and regulating temperature, offers 900 incineration temperature of 25 c. Analytical balance. Electric hot plate or Bunsen. 3, crucible of analysis steps preparation: Crucible mustfirst wash with boiling dilute hydrochloric acid, then wash with a lot of water and then rinse with distilled water. Wash the Crucible within ashing furnace, heated at 900 to 25 ? 30min, and in the desiccator to cool to room temperature and then weighing,}while(N);while(Pop_Seqstack(s,&x)){if(x>=10)/*为了能转为十进制以上的*/printf("%c",x+55);elseprintf("%d",x);}free(s);/*释放顺序栈*/printf("\n");return 1;}4.主函数int main(){Seqstack *s;int choice;datatype x;do{printf("************************************************************ ****\n");printf("1.置空栈 2.判栈空 3.入栈 4.出栈 5.取栈顶元素 6.遍历 7.退出\n");printf("************************************************************ ****\n");printf("请输入选择(1~7):");scanf("%d",&choice);getchar();switch(choice){case 1:s=Init_Seqstack();if(s)printf("置空栈成功!\n");break;case 2:if(Empty_Seqstack(s))printf("此为空栈.\n");elseprintf("此不为空栈.\n");;break;case 3:printf("请输入一个整数:");scanf("%d",&x);if(Push_Seqstack(s,x))printf("入栈成功.\n");elseprintf("栈已满,无法入栈.\n");;break;case 4:if(Pop_Seqstack(s,&x)) acidity, mL.; M--calibration of the molar concentration of sodium hydroxide standard solution, moI/L; V--amount of the volume of sodium hydroxide standard solution, Ml; M--the weight of the sample, g. Such as poor meets the requirements, take the arithmetic mean of the second determination as a result. Results one decimal. 6, allowing differential analyst simultaneously or in quick succession for the second determination, the absolute value of the difference of the results. This value should be no more than 1.0. 1, definitions and principles for determination of ash in starches, starch and ash: starch samples of ash the residue obtained after weight. Original sample residue weight of sample weight or weight expressed as a percentage of the dry weight of the sample. Samples of ash at 900 ? high temperature until ashing sample ... The Crucible: determination of Platinum or other conditions of the affected material, capacity of 50mL. Dryer: has effectively adequate drying agent and-perforated metal plate or porcelain. Ashing furnaces: device for controlling and regulating temperature, offers 900 incineration temperature of 25 c. Analytical balance. Electric hot plate or Bunsen. 3, crucible of analysis steps preparation: Crucible must first wash with boiling dilute hydrochloric acid, then wash with a lot of water and then rinse with distilled water.Wash the Crucible within ashing furnace, heated at 900 to 25 ? 30min, and in the desiccator to cool to room temperature and then weighing, printf("出栈成功,出栈元素为:%d\n",x);elseprintf("出栈失败,因栈为空.\n");break;case 5:if(Top_Seqstack(s,&x))printf("取栈顶元素成功,栈顶元素为:%d\n",x);elseprintf("取栈顶元素失败,因栈为空.\n");break;case 6:Printf_Seqstack(s);break;case 7:printf("谢谢使用!\n");break;default :printf("输入错误,请重新输入!\n");break;}}while(choice!=7);return 0;}二.链栈1.宏定义#include<stdio.h>#include<stdlib.h>#define datatype ****2.结构体typedef struct snode{datatype data;struct snode *next;}Stacknode,*Linkstack;3.基本函数Linkstack Init_Linkstack()/*初始化栈函数1.先决条件:无2.函数作用:初始化链栈,返回top地址*/ { Linkstack top;top=(Linkstack)malloc(sizeof(Stacknode));top->next=NULL;return top;}int Empty_Linkstack(Linkstack top) /*判栈空函数1.先决条件:初始化链栈2.函数作用:判断栈是否为空,空返回1,不空返回0*/{if(top->next==NULL)acidity, mL.; M--calibration of the molar concentration of sodium hydroxide standard solution, moI/L; V--amount of the volume of sodium hydroxide standard solution, Ml; M--the weight of the sample, g. Such as poor meets the requirements, take the arithmetic mean of the second determination as a result. Results one decimal. 6, allowing differential analyst simultaneously or in quick succession for the second determination, the absolute value of the difference of the results. This value should be no more than 1.0. 1, definitions and principles fordetermination of ash in starches, starch and ash: starch samples of ash the residue obtained after weight. Original sample residue weight of sample weight or weight expressed as a percentage of the dry weight of the sample. Samples of ash at 900 ? high temperature until ashing sample ... The Crucible: determination of Platinum or other conditions of the affected material, capacity of 50mL. Dryer: has effectively adequate drying agent and-perforated metal plate or porcelain. Ashing furnaces: device for controlling and regulating temperature, offers 900 incineration temperature of 25 c. Analytical balance. Electric hot plate or Bunsen. 3, crucible of analysis steps preparation: Crucible mustfirst wash with boiling dilute hydrochloric acid, then wash with a lot of water and then rinse with distilled water. Wash the Crucible within ashing furnace, heated at 900 to 25 ? 30min, and in the desiccator to cool to room temperature and then weighing,return 1;else return 0;}int Push_Linkstack(Linkstack top,datatype x) /*入栈函数1.先决条件:初始化链栈2.函数作用:将数据x入栈,成功返回1,失败返回0*/ { Stacknode *p;p=(Stacknode *)malloc(sizeof(Stacknode));p->data=x;p->next=top->next;top->next=p;return 1;}int Pop_Linkstack(Linkstack top,datatype *x) /*出栈函数1.先决条件:初始化链栈2.函数作用:若栈空退出,若没空则将数据出栈,并将其存放到x中,成功返回1,因栈空失败返回0*/{if(top->next==NULL)return 0;Stacknode *p=top->next;*x=p->data;top->next=p->next;free(p);return 1;}int Top_Linkstack(Linkstack top,datatype *x) /*取栈顶元素函数1.先决条件:初始化链栈2.函数作用:取栈顶元素并放到x中,成功返回1,因栈空失败返回0*/{if(top->next==NULL)return 0;*x=top->next->data;return 1;}int Printf_Linkstack(Linkstack top) /*遍历链栈函数1.先决条件:初始化链栈2.函数作用:遍历链栈,成功返回1*/ {Stacknode *p=top->next;int j=0;while(p){printf("%d ",p->data);/*因datatype不同而不同*/j++;if(j%10==0)acidity, mL.; M--calibration of the molar concentration of sodium hydroxide standard solution, moI/L; V--amount of the volume of sodium hydroxide standard solution, Ml; M--the weight of the sample, g. Such as poor meets the requirements, take the arithmetic mean of the second determination as a result. Results one decimal. 6, allowing differential analyst simultaneously or in quick succession for the second determination, the absolute value of the difference of the results. This value should be no more than 1.0. 1, definitions and principles for determination of ash in starches, starch and ash: starch samples of ash the residue obtained after weight. Original sample residue weight of sample weight or weight expressed as a percentage of the dry weight of the sample. Samples of ash at 900 ? high temperature until ashing sample ... The Crucible: determination of Platinum or other conditions of the affected material, capacity of 50mL. Dryer: has effectively adequate drying agent and-perforated metal plate or porcelain. Ashingfurnaces: device for controlling and regulating temperature, offers 900 incineration temperature of 25 c. Analytical balance. Electric hot plate or Bunsen. 3, crucible of analysis steps preparation: Crucible mustfirst wash with boiling dilute hydrochloric acid, then wash with a lot of water and then rinse with distilled water. Wash the Crucible within ashing furnace, heated at 900 to 25 ? 30min, and in the desiccator to cool to room temperature and then weighing,printf("\n");p=p->next;}printf("\n");return 1;}int Conversation_Linkstack(int N,int r)/*数制转换函数(链栈)1.先决条件:具有置空栈,入栈,出栈函数2.函数作用:将N转换为r进制的数*/{Linkstack top;datatype x;printf("%d转为%d进制的数为:",N,r);/*以后可以删除去*/top=Init_Linkstack();do{Push_Linkstack(top,N%r);N=N/r;}while(N);while(Pop_Linkstack(top,&x)){if(x>=10)/*为了能转为十进制以上的*/printf("%c",x+55);elseprintf("%d",x);}printf("\n");free(top);/*释放栈顶空间*/return 1;}4.主函数int main(){Linkstack top;int choice;datatype x;do{printf("************************************************************ ****\n");printf("1.置空栈 2.判栈空 3.入栈 4.出栈 5.取栈顶元素 6.遍历 7.退出\n");printf("************************************************************ ****\n");printf("请输入选择(1~7):");acidity, mL.; M--calibration of the molar concentration of sodium hydroxide standard solution, moI/L; V--amount of the volume of sodium hydroxide standard solution, Ml; M--the weight of the sample, g. Such as poor meets the requirements, take the arithmetic mean of the second determination as a result. Results one decimal. 6, allowing differential analyst simultaneously or in quick succession for the second determination, the absolute value of the difference of the results. This value should be no more than 1.0. 1, definitions and principles for determination of ash in starches, starch and ash: starch samples of ash the residue obtained after weight. Original sample residue weight of sample weight or weight expressed as a percentage of the dry weight of the sample. Samples of ash at 900 ? high temperature until ashing sample ... The Crucible: determination of Platinum or other conditions of the affected material, capacity of 50mL. Dryer: has effectively adequate drying agent and-perforated metal plate or porcelain. Ashing furnaces: device for controlling and regulating temperature, offers 900 incineration temperature of 25 c. Analytical balance. Electric hot plate or Bunsen. 3, crucible of analysis steps preparation: Crucible mustfirst wash with boiling dilute hydrochloric acid, then wash with a lotof water and then rinse with distilled water. Wash the Crucible within ashing furnace, heated at 900 to 25 ? 30min, and in the desiccator to cool to room temperature and then weighing,scanf("%d",&choice);getchar();switch(choice){case 1:top=Init_Linkstack();if(top)printf("置空栈成功!\n");break;case 2:if(Empty_Linkstack(top))printf("此为空栈.\n");elseprintf("此不为空栈.\n");;break;case 3:printf("请输入一个整数:");scanf("%d",&x);if(Push_Linkstack(top,x))printf("入栈成功.\n");elseprintf("栈已满,无法入栈.\n");;break;case 4:if(Pop_Linkstack(top,&x))printf("出栈成功,出栈元素为:%d\n",x);elseprintf("出栈失败,因栈为空.\n");break;case 5:if(Top_Linkstack(top,&x))printf("取栈顶元素成功,栈顶元素为:%d\n",x);elseprintf("取栈顶元素失败,因栈为空.\n");break;case 6:Printf_Linkstack(top);break;case 7:printf("谢谢使用!\n");break;default :printf("输入错误,请重新输入!\n");break;}}while(choice!=7);return 0;}二.队列1.宏定义2.结构体3.基本函数4.主函数acidity, mL.; M--calibration of the molar concentration of sodium hydroxide standard solution, moI/L; V--amount of the volume of sodium hydroxide standard solution, Ml; M--the weight of the sample, g. Such as poor meets the requirements, take the arithmetic mean of the second determination as a result. Results one decimal. 6, allowing differential analyst simultaneously or in quick succession for the second determination, the absolute value of the difference of the results. Thisvalue should be no more than 1.0. 1, definitions and principles for determination of ash in starches, starch and ash: starch samples of ash the residue obtained after weight. Original sample residue weight of sample weight or weight expressed as a percentage of the dry weight of the sample. Samples of ash at 900 ? high temperature until ashing sample ... The Crucible: determination of Platinum or other conditions of the affected material, capacity of 50mL. Dryer: has effectively adequate drying agent and-perforated metal plate or porcelain. Ashing furnaces: device for controlling and regulating temperature, offers 900 incineration temperature of 25 c. Analytical balance. Electric hot plate or Bunsen. 3, crucible of analysis steps preparation: Crucible mustfirst wash with boiling dilute hydrochloric acid, then wash with a lot of water and then rinse with distilled water. Wash the Crucible within ashing furnace, heated at 900 to 25 ? 30min, and in the desiccator to cool to room temperature and then weighing,。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档