Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link
  1. You are including too little. std::unique_ptr needs <memory>, std::swap needs <utility>, std::invalid_argument needs <stdexcept>.

  2. Defining and using a ctor for your Node instead of using aggregate-initialization forces you to make unnecessary, maybe costly or even impossible, copies. Considering your interface, that's very surprising for your clients.

    Remove all ctors from Node, and use aggregate-initialization instead.

Remove all ctors from Node, and use aggregate-initialization instead.

  1. I honestly have no idea why you defined the private .display(std::ostream&). Just put it back into friend std::ostream& operator<<(std::ostream&, SingleLinkedList const&).

  2. Defining .display() needlessly chains your code to std::cout. Otherwise, you could include <ostream> instead of <iostream> and avoid initializing all the C++ streams.

  3. If you want to stream a single character, don't stream a string. Needless inefficiency is bad.

  4. Users expect an iterator-interface, and it would make copying, printing, as well as inserting and deleting at specific points easier and/or more efficient. Enabling use of standard algorithms is also nice.

    You should implement ForwardIterator s.

You should implement ForwardIterator s.

  1. Your names are outlandish (.getSize() => .size(), .push() / insertTail() => .push_back(), .insertHead() => .push_front(), .deleteHead() => .pop_front(), .deleteTail() => .pop_back()). That means no standard algorithms to you, and it's much harder to work with.

  2. I would expect .search() to return an iterator. As you don't have any, maybe a pointer. But certainly not a bool, that's what .contains() would be for.

  3. You don't allow construction from std::initializer_list<T>, nor an Iterator-pair. That's disappointing.

  4. You know pointer != nullptr is the same as pointer in a boolean context? The same for pointer == nullptr and !pointer.

  5. Avoid mixing iostreams and stdio without good reason. Also, only use std::endl if you need an explicit flush. But, maybe you do...

  6. You know you can fuse two string-literals simply by not separating them with anything but whitespace, including newlines?

  1. You are including too little. std::unique_ptr needs <memory>, std::swap needs <utility>, std::invalid_argument needs <stdexcept>.

  2. Defining and using a ctor for your Node instead of using aggregate-initialization forces you to make unnecessary, maybe costly or even impossible, copies. Considering your interface, that's very surprising for your clients.

Remove all ctors from Node, and use aggregate-initialization instead.

  1. I honestly have no idea why you defined the private .display(std::ostream&). Just put it back into friend std::ostream& operator<<(std::ostream&, SingleLinkedList const&).

  2. Defining .display() needlessly chains your code to std::cout. Otherwise, you could include <ostream> instead of <iostream> and avoid initializing all the C++ streams.

  3. If you want to stream a single character, don't stream a string. Needless inefficiency is bad.

  4. Users expect an iterator-interface, and it would make copying, printing, as well as inserting and deleting at specific points easier and/or more efficient. Enabling use of standard algorithms is also nice.

You should implement ForwardIterator s.

  1. Your names are outlandish (.getSize() => .size(), .push() / insertTail() => .push_back(), .insertHead() => .push_front(), .deleteHead() => .pop_front(), .deleteTail() => .pop_back()). That means no standard algorithms to you, and it's much harder to work with.

  2. I would expect .search() to return an iterator. As you don't have any, maybe a pointer. But certainly not a bool, that's what .contains() would be for.

  3. You don't allow construction from std::initializer_list<T>, nor an Iterator-pair. That's disappointing.

  4. You know pointer != nullptr is the same as pointer in a boolean context? The same for pointer == nullptr and !pointer.

  5. Avoid mixing iostreams and stdio without good reason. Also, only use std::endl if you need an explicit flush. But, maybe you do...

  6. You know you can fuse two string-literals simply by not separating them with anything but whitespace, including newlines?

  1. You are including too little. std::unique_ptr needs <memory>, std::swap needs <utility>, std::invalid_argument needs <stdexcept>.

  2. Defining and using a ctor for your Node instead of using aggregate-initialization forces you to make unnecessary, maybe costly or even impossible, copies. Considering your interface, that's very surprising for your clients.

    Remove all ctors from Node, and use aggregate-initialization instead.

  3. I honestly have no idea why you defined the private .display(std::ostream&). Just put it back into friend std::ostream& operator<<(std::ostream&, SingleLinkedList const&).

  4. Defining .display() needlessly chains your code to std::cout. Otherwise, you could include <ostream> instead of <iostream> and avoid initializing all the C++ streams.

  5. If you want to stream a single character, don't stream a string. Needless inefficiency is bad.

  6. Users expect an iterator-interface, and it would make copying, printing, as well as inserting and deleting at specific points easier and/or more efficient. Enabling use of standard algorithms is also nice.

    You should implement ForwardIterator s.

  7. Your names are outlandish (.getSize() => .size(), .push() / insertTail() => .push_back(), .insertHead() => .push_front(), .deleteHead() => .pop_front(), .deleteTail() => .pop_back()). That means no standard algorithms to you, and it's much harder to work with.

  8. I would expect .search() to return an iterator. As you don't have any, maybe a pointer. But certainly not a bool, that's what .contains() would be for.

  9. You don't allow construction from std::initializer_list<T>, nor an Iterator-pair. That's disappointing.

  10. You know pointer != nullptr is the same as pointer in a boolean context? The same for pointer == nullptr and !pointer.

  11. Avoid mixing iostreams and stdio without good reason. Also, only use std::endl if you need an explicit flush. But, maybe you do...

  12. You know you can fuse two string-literals simply by not separating them with anything but whitespace, including newlines?

added 201 characters in body
Source Link
Deduplicator
  • 19.6k
  • 1
  • 32
  • 65
  1. You are including too little. std::unique_ptr needs <memory>, std::swap needs <utility>, std::invalid_argument needs <stdexcept>.

  2. Defining and using a ctor for your Node instead of using aggregate-initialization forces you to make unnecessary, maybe costly or even impossible, copies. Considering your interface, that's very surprising for your clients.

Remove all ctors from Node, and use aggregate-initialization instead.

  1. I honestly have no idea why you defined the private .display(std::ostream&). Just put it back into friend std::ostream& operator<<(std::ostream&, SingleLinkedList const&).

  2. Defining .display() needlessly chains your code to std::cout. Otherwise, you could include <ostream> instead of <iostream> and avoid initializing all the C++ streams.

  3. If you want to stream a single character, don't stream a string. Needless inefficiency is bad.

  4. Users expect an iterator-interface, and it would make copying, printing, as well as inserting and deleting at specific points easier and/or more efficient. Enabling use of standard algorithms is also nice.

You should implement ForwardIterator s.

  1. Your names are outlandish (.getSize() => .size(), .push() / insertTail() => .push_back(), .insertHead() => .push_front(), .deleteHead() => .pop_front(), .deleteTail() => .pop_back()). That means no standard algorithms to you, and it's much harder to work with.

  2. I would expect .search() to return an iterator. As you don't have any, maybe a pointer. But certainly not a bool, that's what .contains() would be for.

  3. You don't allow construction from std::initializer_list<T>, nor an Iterator-pair. That's disappointing.

  4. You know pointer != nullptr is the same as pointer in a boolean context? The same for pointer == nullptr and !pointer.

  5. Avoid mixing iostreams and stdio without good reason. Also, only use std::endl if you need an explicit flush. But, maybe you do...

  6. You know you can fuse two string-literals simply by not separating them with anything but whitespace, including newlines?

  1. You are including too little. std::unique_ptr needs <memory>, std::swap needs <utility>, std::invalid_argument needs <stdexcept>.

  2. Defining and using a ctor for your Node instead of using aggregate-initialization forces you to make unnecessary, maybe costly or even impossible, copies. Considering your interface, that's very surprising.

  3. I honestly have no idea why you defined the private .display(std::ostream&). Just put it back into friend std::ostream& operator<<(std::ostream&, SingleLinkedList const&).

  4. Defining .display() needlessly chains your code to std::cout. Otherwise, you could include <ostream> instead of <iostream> and avoid initializing all the C++ streams.

  5. If you want to stream a single character, don't stream a string. Needless inefficiency is bad.

  6. Users expect an iterator-interface, and it would make copying, printing, as well as inserting and deleting at specific points easier and/or more efficient. Enabling use of standard algorithms is also nice.

  7. Your names are outlandish (.getSize() => .size(), .push() / insertTail() => .push_back(), .insertHead() => .push_front(), .deleteHead() => .pop_front(), .deleteTail() => .pop_back()). That means no standard algorithms to you, and it's much harder to work with.

  8. I would expect .search() to return an iterator. As you don't have any, maybe a pointer. But certainly not a bool, that's what .contains() would be for.

  9. You don't allow construction from std::initializer_list<T>, nor an Iterator-pair. That's disappointing.

  10. You know pointer != nullptr is the same as pointer in a boolean context? The same for pointer == nullptr and !pointer.

  11. Avoid mixing iostreams and stdio without good reason. Also, only use std::endl if you need an explicit flush. But, maybe you do...

  12. You know you can fuse two string-literals simply by not separating them with anything but whitespace, including newlines?

  1. You are including too little. std::unique_ptr needs <memory>, std::swap needs <utility>, std::invalid_argument needs <stdexcept>.

  2. Defining and using a ctor for your Node instead of using aggregate-initialization forces you to make unnecessary, maybe costly or even impossible, copies. Considering your interface, that's very surprising for your clients.

Remove all ctors from Node, and use aggregate-initialization instead.

  1. I honestly have no idea why you defined the private .display(std::ostream&). Just put it back into friend std::ostream& operator<<(std::ostream&, SingleLinkedList const&).

  2. Defining .display() needlessly chains your code to std::cout. Otherwise, you could include <ostream> instead of <iostream> and avoid initializing all the C++ streams.

  3. If you want to stream a single character, don't stream a string. Needless inefficiency is bad.

  4. Users expect an iterator-interface, and it would make copying, printing, as well as inserting and deleting at specific points easier and/or more efficient. Enabling use of standard algorithms is also nice.

You should implement ForwardIterator s.

  1. Your names are outlandish (.getSize() => .size(), .push() / insertTail() => .push_back(), .insertHead() => .push_front(), .deleteHead() => .pop_front(), .deleteTail() => .pop_back()). That means no standard algorithms to you, and it's much harder to work with.

  2. I would expect .search() to return an iterator. As you don't have any, maybe a pointer. But certainly not a bool, that's what .contains() would be for.

  3. You don't allow construction from std::initializer_list<T>, nor an Iterator-pair. That's disappointing.

  4. You know pointer != nullptr is the same as pointer in a boolean context? The same for pointer == nullptr and !pointer.

  5. Avoid mixing iostreams and stdio without good reason. Also, only use std::endl if you need an explicit flush. But, maybe you do...

  6. You know you can fuse two string-literals simply by not separating them with anything but whitespace, including newlines?

added 5 characters in body
Source Link
Deduplicator
  • 19.6k
  • 1
  • 32
  • 65
  1. You are including too little. std::unique_ptr needs <memory>, std::swap needs <utility>, std::invalid_argument needs <stdexcept>.

  2. Defining and using a ctor for your Node instead of using aggregate-initialization forces you to make unnecessary, maybe costly or even impossible, copies. Considering your interface, that's very surprising.

  3. I honestly have no idea why you defined the private .display(std::ostream&). Just put it back into friend std::ostream& operator<<(std::ostream&, SingleLinkedList const&).

  4. Defining .display() needlessly chains your code to std::cout. Otherwise, you could include <ostream> instead of <iostream> and avoid initializing all the C++ streams.

  5. If you want to stream a single character, don't stream a string. Needless inefficiency is bad.

  6. Users expect an iterator-interface, and it would make copying, printing, as well as inserting and deleting at specific points easier and/or more efficient. Enabling use of standard algorithms is also nice.

  7. Your names are outlandish (.getSize() => .size(), .push() / insertTail() => .push_back(), .insertHead() => .push_front(), .deleteHead() => .pop_front(), .deleteTail() => .pop_back()). That means no standard algorithms to you, and it's much harder to work with.

  8. I would expect .search() to return an iterator. As you don't have any, maybe a pointer. But certainly not a bool, that's what .contains() would be for.

  9. You don't allow construction from std::initializer_list<T>, nor an Iterator-pair. That's disappointing.

  10. You know pointer != nullptr is the same as pointer in a boolean context? The same for pointer == nullptr and !pointer.

  11. Avoid mixing iostreams and stdio without good reason. Also, only use std::endl if you need an explicit flush. But, maybe you do...

  12. You know you can fuse two string-literals simply by not separating them bywith anything but whitespace, including newlines?

  1. You are including too little. std::unique_ptr needs <memory>, std::swap needs <utility>, std::invalid_argument needs <stdexcept>.

  2. Defining and using a ctor for your Node instead of using aggregate-initialization forces you to make unnecessary, maybe costly or even impossible, copies. Considering your interface, that's very surprising.

  3. I honestly have no idea why you defined the private .display(std::ostream&). Just put it back into friend std::ostream& operator<<(std::ostream&, SingleLinkedList const&).

  4. Defining .display() needlessly chains your code to std::cout. Otherwise, you could include <ostream> instead of <iostream> and avoid initializing all the C++ streams.

  5. If you want to stream a single character, don't stream a string. Needless inefficiency is bad.

  6. Users expect an iterator-interface, and it would make copying, printing, as well as inserting and deleting at specific points easier and/or more efficient. Enabling use of standard algorithms is also nice.

  7. Your names are outlandish (.getSize() => .size(), .push() / insertTail() => .push_back(), .insertHead() => .push_front(), .deleteHead() => .pop_front(), .deleteTail() => .pop_back()). That means no standard algorithms to you, and it's much harder to work with.

  8. I would expect .search() to return an iterator. As you don't have any, maybe a pointer. But certainly not a bool, that's what .contains() would be for.

  9. You don't allow construction from std::initializer_list<T>, nor an Iterator-pair. That's disappointing.

  10. You know pointer != nullptr is the same as pointer in a boolean context? The same for pointer == nullptr and !pointer.

  11. Avoid mixing iostreams and stdio without good reason. Also, only use std::endl if you need an explicit flush. But, maybe you do...

  12. You know you can fuse two string-literals simply not separating them by anything but whitespace, including newlines?

  1. You are including too little. std::unique_ptr needs <memory>, std::swap needs <utility>, std::invalid_argument needs <stdexcept>.

  2. Defining and using a ctor for your Node instead of using aggregate-initialization forces you to make unnecessary, maybe costly or even impossible, copies. Considering your interface, that's very surprising.

  3. I honestly have no idea why you defined the private .display(std::ostream&). Just put it back into friend std::ostream& operator<<(std::ostream&, SingleLinkedList const&).

  4. Defining .display() needlessly chains your code to std::cout. Otherwise, you could include <ostream> instead of <iostream> and avoid initializing all the C++ streams.

  5. If you want to stream a single character, don't stream a string. Needless inefficiency is bad.

  6. Users expect an iterator-interface, and it would make copying, printing, as well as inserting and deleting at specific points easier and/or more efficient. Enabling use of standard algorithms is also nice.

  7. Your names are outlandish (.getSize() => .size(), .push() / insertTail() => .push_back(), .insertHead() => .push_front(), .deleteHead() => .pop_front(), .deleteTail() => .pop_back()). That means no standard algorithms to you, and it's much harder to work with.

  8. I would expect .search() to return an iterator. As you don't have any, maybe a pointer. But certainly not a bool, that's what .contains() would be for.

  9. You don't allow construction from std::initializer_list<T>, nor an Iterator-pair. That's disappointing.

  10. You know pointer != nullptr is the same as pointer in a boolean context? The same for pointer == nullptr and !pointer.

  11. Avoid mixing iostreams and stdio without good reason. Also, only use std::endl if you need an explicit flush. But, maybe you do...

  12. You know you can fuse two string-literals simply by not separating them with anything but whitespace, including newlines?

Source Link
Deduplicator
  • 19.6k
  • 1
  • 32
  • 65
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /