Table of Content. One Dimensional Array All Programs. C Program to Implement Stack Operations Using Array; C Program to Perform Stack Operations Using Pointer! C program for stack with array implementation 2013-10-22 22:28 166 人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载。 用数组实现stack. C program for stack with array implementation. C程序。必须先初始化栈,然后才能用。要初始化S- > top的值。#include< stdio. N 1. 00. 0typedef struct {int data[N]; int top; }stackseq; void initial(stackseq *S){S- > top = - 1; printf("Initial is finish!n"); }int empty(stackseq *S){if(S- > top==- 1){printf("Empty!n"); return true; }else return false; }void Push(stackseq *S, int x){if(S- > top< N){S- > top++; S- > data[S- > top]=x; } else {printf("The stack is full!n"); exit(0); } }void display(stackseq *S){int i; for(i=S- > top; i> =0; i- -)printf("%d ", S- > data[i]); }int Pop(stackseq *S){if(empty(S)){ printf("underflow"); return 0; } else{S- > top- -; return S- > data[S- > top+1]; } }int main(){int select,x,y,c; stackseq S; do{// printf("n"); printf("n. S); break; case 2: empty(& S); // printf("%dn",c); break; case 3: printf("please input a data: "); scanf("%d",& x); printf("n"); Push(& S,x); //display(& S); break; case 4: c=Pop(& S); printf("出栈元素: %dn",c); //display(& S); break; case 5: printf("n 请打印栈中的所有元素n"); display(& S); break; //case 4: // stacklen(& S); case 0: exit(0); break; }}while (select!=0); system("pause"); return 0; } 测试结果:1- intial 2- push 3- pop 0- exitplease select(1,2,3,4,5,0): 1. Initial is finish! Empty! 1- intial 2- push 3- pop 0- exitplease select(1,2,3,4,5,0): 3please input a data: 5. Stack program in c: C program to implement stack using array. C programming code. #include <stdio.h> #include <stdlib.h> int stack [5]; void push (); int pop (); void. It is using the array implementation of the stacks and supposed to evalu. Array implementation of stack. How to implement pop for a stack as an array program? High Light-Load Efficient 120VAC Input, 25W/5VDC Reference Design with 4 POL Outputs. Implementation of stack using array C Program to. stack using c, stack implementation using array,implement stack. implementation of stack using array. Stack - Array Implementation. when writing the stack in C. Finally, while the array that holds the contents. stack.c). Also, here's a sample main program. Here is source code of the C program to implement a stack. The C program is successfully compiled and run on a. « C Program to Read an Array and Search for an. Empty! underflow出栈元素: 0. N 1. 00. 0//int static count=0; typedef struct {int data[N]; int top; }stackseq; void initial(stackseq *S){S- > top = - 1; printf("Initial is finish!n"); }int empty(stackseq *S){if(S- > top==- 1){//printf("Empty!n"); return true; }else return false; }void Push(stackseq *S, int x){if(S- > top< N){S- > top++; printf("请输入第 %d 次进栈元素: ",S- > top+1); scanf("%d",& x); S- > data[S- > top]=x; } else {printf("The stack is full!n"); exit(0); } }void display(stackseq *S){int i; // int t; //printf("t=%d",empty(S)); if(!(empty(S))){ printf("n 请打印栈中的所有元素n"); for(i=S- > top; i> =0; i- -)printf("%d ", S- > data[i]); } else printf("The stack is empty!n"); }int Pop(stackseq *S){ static int count=0; //尽量少用静态存储变量,因为它在程序调用时一直存在,长时间占用内存。if(empty(S)){ printf("underflow"); return 0; } else{S- > top- -; count++; printf("请输入第%d次出栈元素: %d ",count,S- > data[S- > top+1]); return S- > data[S- > top+1]; } }int main(){int select,x,y,c; stackseq S; do{// printf("n"); printf("n. S); break; case 2: empty(& S); break; case 3: //printf("请输入第 %d 次进栈元素: ",S- > top+1); // scanf("%d",& x); printf("n"); Push(& S,x); break; case 4: Pop(& S); //c=Pop(& S); //printf("出栈元素: %dn",c); break; case 5: display(& S); break; //case 4: // stacklen(& S); case 0: exit(0); break; }}while (select!=0); system("pause"); return 0; } 运行结果:1- intial 2- push 3- pop 0- exitplease select(1,2,3,0): 1. Initial is finish! The stack is empty! I am trying a stack implementation using an array. I want to know if this approach is OK or if there is a logical problem. This program is working fine. #include <. . Thandalam. INDEX 1. Array Implementation Of Stack 2. Application Of Stack. 1 Date : ARRAY IMPLEMENTATION OF STACK Aim To write a C-program to.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
September 2016
Categories |