diff --git a/homework3/Stack.cpp b/homework3/Stack.cpp index 66c3450..b6766df 100644 --- a/homework3/Stack.cpp +++ b/homework3/Stack.cpp @@ -37,5 +37,6 @@ int pop(stack &s) { return NULL; } int e = s.data[s.top]; + s.top--; return e; } diff --git a/homework3/test1.cpp b/homework3/test1.cpp index 7a19bbc..d6f5983 100644 --- a/homework3/test1.cpp +++ b/homework3/test1.cpp @@ -2,7 +2,23 @@ #include using namespace std; -int main() { +string getBinary(int i) { + stack s; + initStack(s); + while (i != 0) { + push(s, i % 2); + i /= 2; + } + string str = ""; + while (!isEmpty(s)) { + str += pop(s) + '0'; + } + return str; +} +int main() { + int decimal; + cin >> decimal; + cout << getBinary(decimal) << endl;; return 0; }