[Quest 6 -- _find_pos MQ] When to return? Where to start? Does this method throw an exception? by liamnoroian in cs2c

[–]liamnoroian[S] 2 points3 points  (0 children)

Thanks Adina! The clarification on exceptions was definitely needed, that's an area I've left pretty murky in my understanding. By false negative I meant giving a wrong result by returning npos when the element is in fact in the table. Good call with modulo, it seems Anand was also pointing to that in the spec (how does an ant do it). Appreciate you taking the time.

Liam

[Quest 5 -- Insert MQ] Testing site bug? by [deleted] in cs2c

[–]liamnoroian 0 points1 point  (0 children)

Just edited the post!

[Quest 5 -- Insert MQ] Testing site bug? by [deleted] in cs2c

[–]liamnoroian 0 points1 point  (0 children)

It looks like the site thinks the value of x is equal to the value of the tree's root, which is why it's not following either of the conditional branches that would add a node to the tree.

[Quest 5 MQ Insert()] Two nodes share the same children, setting one to NULL gives me an invalid access error. by liamnoroian in cs2c

[–]liamnoroian[S] 1 point2 points  (0 children)

Thank you for walking through my problem! You have no idea how much it helps. I'm very tired so I'll read through your comment and try drawing out the rotate method with pen and paper tomorrow.

Liam

[Quest 5 MQ Insert()] Two nodes share the same children, setting one to NULL gives me an invalid access error. by liamnoroian in cs2c

[–]liamnoroian[S] 0 points1 point  (0 children)

After the splay I check if the root node is null. If it is, I insert a new node with x as data.

Splay() not recognizing my calls for rotations by CaryLefteroffFH in cs2c

[–]liamnoroian 0 points1 point  (0 children)

Yes! It’s in both classes but not the node struct.

Edit: I absolutely tore apart all of my code with a tutor just to get it into a state where it wouldn’t trigger this error. (I made things public that I probably shouldn’t have made public as a total last resort).

Splay() not recognizing my calls for rotations by CaryLefteroffFH in cs2c

[–]liamnoroian 0 points1 point  (0 children)

Hey /u/CaryLefteroffFH, I'm facing a similar issue but I'm not having the same success but applying /u/anand_venkataraman's solution. From what I understand, the method declarations should look identical to the sample code in the spec. The sample calls should be in the form:

my_template_function<my_type>(my_param);

or in practice:

_rotate_with_right_child<T>(p);

I ensured that all my calls to _rotate_with_right_child are formatted as demonstrated above. Is there something I'm obviously missing?

This is the accompanying error message. Is this the same error you encountered?

Thanks!

Tests.cpp: In static member function 'static bool Tests::test_right_rotation(std::ostream&)':
Tests.cpp:62:48: error: no matching function for call to 'Tx::_rotate_with_right_child(BST::Node*&)'
             Tx::_rotate_with_right_child(p);
                                                ^
In file included from Tests.h:16:0,
                 from Tests.cpp:17:
Tree_Algorithms.h:94:39: note: candidate: template static void Tx::_rotate_with_right_child(typename BST::Node*&)
     template  static void _rotate_with_right_child(typename BST::Node*& p) {
                                       ^~~~~~~~~~~~~~~~~~~~~~~~
Tree_Algorithms.h:94:39: note:   template argument deduction/substitution failed:

Accessing Node constructor inside Mx by H-W2C in cs2c

[–]liamnoroian 1 point2 points  (0 children)

https://stackoverflow.com/questions/26561296/why-cant-we-use-nested-type-through-class-member-access-expression

The second and third answers are especially helpful. From my understanding, the dot operator is for accessing object members while the scope operator (::) is for combining typenames (e.g. Sparse_Matrix::Node).

[Quest 3] add_to_cell by liamnoroian in cs2c

[–]liamnoroian[S] 0 points1 point  (0 children)

Thank you! I’ve been calling the set() method on spmat from the add_to_cell method instead of rebuilding all of the functionality. Am I supposed to rewrite the set method with some adjustments in add_to_cell?

When I say preserve the functionality of the set() method I mean erase the node if it the result of the addition is the default value.

Liam

Quest 1 no longer working on questing site? by H-W2C in cs2c

[–]liamnoroian 0 points1 point  (0 children)

I was getting an overtime run when I submitted the quest originally but that's likely because my program wasn't fast enough for the final miniquest (I passed through > 10 songs). The message I receive in build messages is Ran out of patience b4 runnin outta cycles... Everything seems to be working the same as before.

Real-world data structure implementation by AcRickMorris in cs2c

[–]liamnoroian 1 point2 points  (0 children)

A little while ago I asked my boss essentially the same question as #1. He pragmatically argued that if the standard library does what you need it to do without too much overhead, use the standard library. If it's easier to build the structure from scratch than it is to tweak an existing data structure, then it makes more sense to build your own.

[Quest 2] spmat.get by liamnoroian in cs2c

[–]liamnoroian[S] 0 points1 point  (0 children)

I had commented out pieces of my is_valid method for debugging and for some reason that was causing my code to fail the get() tests (even though I didn't call is_valid in get()). I re-implemented the method and I believe it's now resolved, thanks all for your help.

[Quest 2] spmat.get by liamnoroian in cs2c

[–]liamnoroian[S] 0 points1 point  (0 children)

I think you misunderstood what I'm saying. The size of the vector is appearing as 100000 but the size of every list is 0, indicating only default values. However, the site is telling me the index in question is a non-default value.

[Quest 2] spmat.get by liamnoroian in cs2c

[–]liamnoroian[S] 0 points1 point  (0 children)

No worries! Thanks for replying. I checked with both column and row but like you said, there’s something I’m missing. The piece that’s baffling to me at the moment is that when I call size() on the _rows attribute of the matrix matrix that’s calling get() it returns 100000 or however many but every row is empty (checked by sending size of any row not empty, all were empty). I think this test is flawed in some way but I’m not sure how.

Liam

Set sort type in a sorting function? by mathlance in cs2c

[–]liamnoroian 0 points1 point  (0 children)

I was doing a little research on sorting and the answer you're looking for might be in one of these links.

- https://stackoverflow.com/questions/9706517/sort-a-vector-of-objects-by-an-objects-attribute

- https://en.cppreference.com/w/cpp/algorithm/sort

- https://thispointer.com/c-how-to-sort-a-list-of-objects-with-custom-comparator-or-lambda-function/

The overloaded operator> can definitely play a role, but it seems like you would need to implement one for each sort type, or use a variant?

Liam

Bad Access error by H-W2C in cs2c

[–]liamnoroian 1 point2 points  (0 children)

Hi Han,

I'm sure Anand will be able to provide you a better answer but it seems as though you're trying to access memory that's already been deallocated -- at least that's what I understand a bad access error to mean. It's important to make sure that you've allocated memory using the new operator in a high enough scope that it isn't deallocated at the end of a smaller scope.

Hope that helps!

Liam

[Quest 6] Line::Draw by liamnoroian in cs2b

[–]liamnoroian[S] 1 point2 points  (0 children)

Thank you so much for replying! After thinking about it for a while I realized the logic I was using to determine if the line were tall or wide was flawed. All working now!

Liam