-
Notifications
You must be signed in to change notification settings - Fork 7
Stack - C++ #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Stack - C++ #14
Conversation
|
Nu am stiut cum sa tratez cazul in care fac "peek" pe stiva goala asa ca am pus exit. |
| using namespace std; | ||
|
|
||
| template <typename T> | ||
| class stack { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/stack/ArrayStack
|
|
||
| template <typename T> | ||
| class stack { | ||
| public: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variabile publice? why?
| template <typename T> | ||
| class stack { | ||
| public: | ||
| T *arr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tab-uri de 2/4 spatii, te rog
| template <typename T> | ||
| class stack { | ||
| public: | ||
| T *arr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/arr/array
| class stack { | ||
| public: | ||
| T *arr; | ||
| int top; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ai nevoie si de top si de size?
| size_t capacity; | ||
| size_t size; | ||
|
|
||
| stack (size_t capacity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creeaza doar un constructor simplu fara capacitate; nimeni nu foloseste Stack(123), ci Stack()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
poti pune capacitatea initiala ca o constanta
| arr[++top] = data; | ||
| ++size; | ||
| } else { | ||
| T *arr2 = new T[capacity * 2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/arr2/new_array
|
|
||
| T peek() { | ||
| if (is_empty()) { | ||
| exit(-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Poti folosi -std=c++17 si "optional".
Check it out here: https://github.com/NITSkmOS/Algorithms/blob/master/queue/cpp/Queue.h
Or here: https://en.cppreference.com/w/cpp/utility/optional
| } | ||
|
|
||
| bool is_empty() { | ||
| if (size != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return size == 0;
| }; | ||
|
|
||
| int main() | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
un mic proof of concept aici
No description provided.