Skip to content

Conversation

@andreidinu
Copy link

No description provided.

@andreidinu
Copy link
Author

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 {
Copy link
Owner

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:
Copy link
Owner

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;
Copy link
Owner

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;
Copy link
Owner

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;
Copy link
Owner

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) {
Copy link
Owner

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()

Copy link
Owner

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];
Copy link
Owner

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

bool is_empty() {
if (size != 0) {
Copy link
Owner

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()
{
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants