Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- using namespace std;
- class Stiva {
- int max;
- char *t;
- int top;
- public:
- Stiva(int max) {
- this->max= max;
- this->t = new char[max];
- this->top = -1;
- }
- void push(char c) {
- if(top < max-1){
- t[++top]=c;
- } else {
- cerr<<"Eroare. Depasire capacitate\n";
- exit(1);
- }
- }
- char pop() {
- return t[top--];
- }
- bool isEmpty() {
- /*
- if(top == -1)
- return true;
- else
- return false;
- */
- return top == -1;
- }
- bool isFull() {
- return top == max-1;
- }
- };
- int main() {
- /* Varianta cu cu tablou de caractere */
- /*
- int i;
- char input[100]="abcde";
- char output[100];
- Stiva stiva(strlen(input));
- for(i=0;i<strlen(input);i++){
- stiva.push(input[i]); // iau fiecare caracter din sirul de intrare si il pun in stiva.
- }
- i=0;
- while (!stiva.isEmpty()) {
- output[i]= stiva.pop();
- i++;
- }
- output[i]='\0';
- cout<<output;
- */
- string input = "abcde";
- string output;
- Stiva stiva(input.length());
- for(int i=0; i<input.length(); i++) {
- stiva.push(input[i]); // iau fiecare caracter din sirul de intrare si il pun in stiva.
- }
- output = "";
- while (!stiva.isEmpty()) {
- output = output + stiva.pop(); //caracterul scos din stiva cu pop() e adaugat la output
- }
- cout<<output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement