# #include
# #include
#
# const int TPILA=5; // TPILA es el valor maximo de elementos
# // que puede tener nuestra pila
#
# class PILA{
# public:
# int mipila[TPILA]; // Crea mi PILA de tamano TPILA
# int apilados; // Numero de objetos en LA PILA
# void reset(); // Vacia LA PILA
# void push(int v); // Agrega Valores en el tope de la PILA
# int pop(); // Retorna y elimina el tope de la PILA
# };
#
# void PILA::reset() // Vacia la PILA
# {
# apilados=0;
# }
#
# //Se Agrega(PUSH) un valor en el tope de la pila
# void PILA::push(int v)
# {
# // Comprueba que haya espacio dentro de la pila
# // para poder agregar el nuevo valor
# if(apilados
# {
# mipila[apilados++]=v;
# }
# }
#
# // Se Elimina (POP) el ultimo valor de la pila
# // y retorna el nuevo tope
# int PILA::pop()
# {
# if(apilados>0)
# {
# cout<<"El valor del tope eliminado era: ";
# // Retorna el valor del tope que fue eliminado
# return(mipila[--apilados]);
# }
# else
# cout<<"No existen datos para eliminar. ERROR ";
# return (0);
# }
#
# main()
# {
# PILA stack;
# stack.reset();
# int opc, i, dato;
# char out;
# do
# {
# do
# {
# clrscr();
# cout<<"El siguiente programa simula el funcionamiento de"<
# cout<<"una pila y es capaz de apilar un max. de 5 Valores"< # cout<<"numericos enteros, para fines practicos\n\n"; # cout<<"Que operacion desea Realizar\n\n"; # cout<<"1.- Insertar un dato\n"; # cout<<"2.- Borrar un dato\n"; # cout<<"3.- Mostrar pila\n"; # cout<<"4.- Resetear Pila\n"; # cout<<"5.- Salir"; # cout<<"\n\n\nOpcion(1-5): "; # cin>>opc; # } # while(opc>5); # # switch(opc) # { # case(1): # if(stack.apilados # { # cout<<"dato?: "; # cin>>dato; # stack.push(dato); # } # else # cout<<"ERROR! PILA LLENA!"; # cout<<"\n\nSalir?? (S/N): "; cin>>out; # break; # case(2): # cout< # cout<<"\n\nSalir?? (S/N): "; cin>>out; # break; # case(3): # if(stack.apilados!=0) # { # cout<<"Los datos en la pila actualmente son: "< # for(i=0;i # { cout< # } # else # cout<<"No existen datos en la pila"< # cout<<"\n\nSalir?? (S/N): "; cin>>out; # break; # case(4): # stack.reset(); # cout<<"\n\nSalir?? (S/N): "; cin>>out; # break; # case(5): # out='s'; break; # default: # out='s'; break; # } # } # while(out=='n' out=='N'); # }
There are not Stack implementation in standard C libraries. In order to get stack functionality you will need to write your own implementation.
I suggest to read you web links attached to this question for detailed information about stack and it's implementation in C.
It would be easier to manipulate the stack in assembly language rather than C++.
Two little problems: 1. stack doesn't have a flow-chart 2. there are no flow-charts in a C program
C: there are no methods in C. C++: no.
what ever you assume
http://www.osix.net/modules/article/?id=275muzzy writes "Here's some code for you kids. It demonstrates the concept of stack, implemented with a linked list mechanism to support virtually infinitely large stack sizes. Happy reading."/* Simple Dynamically Allocating Stack Implementation in C** Copyright (C) 2002 Muzzy of Worst Coders*/
What do you mean by stack-refreshing? Anyway, there are no stack handling functions in the standard C library.
You would do this if you implement a stack using an array. Using a zero-based index to keep track of the top of the stack (the end of the array) means we must use the value -1 to indicate an empty stack. This is because an array of n elements will have indices 0 through n-1, where index n-1 represents the element at top of the stack. An empty stack has 0 elements, therefore the top of the stack is represented by index -1.
It would be easier to manipulate the stack in assembly language rather than C++.
On the stack.
int top=-1; int stack[10];
Raymond C. Stack has written: 'Marketing Montana hay' -- subject- s -: Hay trade, Statistics, Hay
C: there are no methods in C. C++: no.
Two little problems: 1. stack doesn't have a flow-chart 2. there are no flow-charts in a C program
ujkjkyjljlui kukhjkui
yes
stack abstract datatype
what ever you assume