Skip to content

hw6+7+9: my linked list#239

Open
anton-kultsov wants to merge 4 commits intomaciekgajewski:masterfrom
anton-kultsov:master
Open

hw6+7+9: my linked list#239
anton-kultsov wants to merge 4 commits intomaciekgajewski:masterfrom
anton-kultsov:master

Conversation

@anton-kultsov
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Owner

@maciekgajewski maciekgajewski left a comment

Choose a reason for hiding this comment

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

Nice! Few const-correctness violations and style issues.

Comment thread course7/homeworks/anton/dc/complex.h Outdated
return Complex((mR*rhs.mR - mI*rhs.mI)/denomenator, (mI*rhs.mR - mR*rhs.mI)/denomenator);
}

bool operator==(const Complex& rhs)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This method should be const, otherwise you wold't be able to compare const objects.

{
std::stack<Complex> tmp_stack;
Stack tmp_stack;
while(!stack.empty()) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Once you implemented the iterators, you should be able to just iterate over the stack here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@maciekgajewski please could you elaborate? std::stack doesn't expose begin and end methods

std::size_t mSize = 0;

public:
typedef Complex value_type;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Prefer using (modern) using over obsolete typedef


reference back() {
if (!mHead)
throw std::range_error("Stack is empty");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is correct, but please note: the standard library containers don't do such checks. They just require the programmer to ensure that the container is in valid state before calling certain methods.

This is a manifestation of "don't pay for what you are not using" principle.

Comment thread course7/homeworks/anton/dc/tests.cc Outdated
c.pop_back();
assert_size(c, 0);

std::cout << "OK for " << typeid(T).name() << std::endl;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Consider using boost::typeindex to get nice, human-readable type name

Comment thread course7/homeworks/anton/dc/tests.cc Outdated
list.push_back(Complex(2, 2));
list.push_back(Complex(3, 3));

double summ = double();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

0.0 would do.

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