Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

types - Stack ADT C++ Functions

So recently i started to getting into stacks ADT in c++ and i am trying to create a small program which the user inserts a string and the output should be in reverse order But something is going wrong with my code or i am missing something but i cant figure it out My output so far is that i can insert the string but then it just output the couts "Reverse string" and nothing else i tried several ways like to change the pop function but nothing changed Thank you for any help

#include <iostream>
#include <string>

using namespace std;
class ReverseString {
public:
     string str[13];
     int topStack;

ReverseString() {
    topStack = -1;
}

string Push() {
    //char item;
    string str("");
    
    cout << "Enter a string " << endl;
    cin >> str;
    
    for (char ch : str) {

        topStack++;
//          str[topStack] = item;
        return str;
    }
}

string Pop() {
    string temp= str[topStack];
    
    for (int i = 0; i <= 13; i++) {
        str[i] = temp;
        //temp = str[i - 1];
        cout << "Reverse String: " << str[topStack] << endl; 
    
        return temp; 
    }
    }
};

// main function
int main() {
    
    ReverseString str;
    str.Push();
    str.Pop();

    return 0;
}
question from:https://stackoverflow.com/questions/65926285/stack-adt-c-functions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...