1、栈、队的实现和运算四、实验结果(源程序)与数据处理(程序运行结果、截图等).实验部分代码:1.#include#define MAXN 26char stackMAXN;int top=0;int push(char x) if (top = MAXN) return(1); stacktop+=x;return(0);int pop(char *p_y) if (top = 0)*p_y = stack-top;void main() int i; char ch_x,ch_y; printf(input the char you want to pushn); scanf(%c,&ch_x
2、); while(ch_x!=0) if (push(ch_x)=1)failure!n else printf(success!input a char for ch_x to pushnch_x= getchar(); i=0; while(stacki!0%c , stacki); i+; if (pop(&ch_y)=1)The pop char is %cn,ch_y); for (i=top-1; i=0; i-)2.#include struct nodechar data; struct node *link;typedef struct node NODE;NODE * to
3、p = NULL;void push_l(char x) NODE *p;p = (NODE * )malloc(sizeof(NODE);p-data = x;link = top;top = p;int pop_l(char *p_y)if (top = NULL)* p_y = top-data;p = top;top = top-link;free(p); NODE *p; push_l(ch_x); p=(NODE*)malloc(sizeof(NODE); p=top; while(p!=NULL),p-data); p=p- if (pop_l(&3.#define MAXN 2
4、6char qMAXN;int head = -1, tail = -1;int en_queue(char x ) if (tail = MAXN-1) q+tail = x; return(0);int de_queue(char *p_y ) if (head = tail) *p_y = q+head;input the char you want to enqueuen if (en_queue(ch_x)=1)input a char for ch_x to enqueuench_x= i=1; while(qi!, qi); if (de_queue(&The dequeue c
5、har is %cn for (i=head+1; ilink = p;tail = p;int de_queue_l(char *p_y)*p_y = head-p = head;head = head- en_queue_l(ch_x); p=head; if (de_queue_l(&5#includeint head = 0, tail = 0;int en_c_q(char x) tail = (tail + 1) % MAXN; if (tail = head) if (tail = 0) tail = MAXN-1;else tail-; qtail = x;int de_c_q(char *p_y)return(1);head = (head+1) % MAXN;*p_y = qhead; if (en_c_q(ch_x)=1) if (de_c_q(&截图五、试验中遇到的问题、分析与讨论。在实验中了解到,在函数调用时,第一个进栈的是主函数中后的下一条指令(函数调用语句的下一条可执行语句)的地址,然后是函数的各个参数,在大多数的C编译器中,参数是由右往左入栈的,然后是函数中的局部变量。注意静态变量是不入栈的。成绩:
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1