Thread: Circular Lists

  1. #61
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    You haven't beat the challenge. You implemented a buggy and effectively unusable linked list. The challenge was to beat my feat, however.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #62
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Buggy how? it compiles on my system just fine. I even made modification's to make it portable, even though that wasnt part of the original challenge. Since noone bothered ot point out the one really obvious bug (caused by a bad copy/past) I can only assume that noone bothered to even attempt to compile it.
    Last edited by abachler; 03-05-2008 at 05:03 PM.

  3. #63
    The larch
    Join Date
    May 2006
    I may be mistaken but the Heap functions appear also to come from <windows.h>. Why don't you just stick with malloc and free?

    Not sure what this challenge is all about, but your List class only allows you to Create, Insert, Delete and Remove things. As a class it is useless: it doesn't take care of anything behind the back, it is entirely up to the user to provide all functionality and encapsulation to make this even remotely useful. Basically it is up to the user to manage the internals of the list class.

    This class design is not really acceptable in C++. You might start by getting acquainted with the private keyword if you want to write anything but plain and messy C with some C++ keywords here and there.

    Come on, you are not the only one here who could easily implement a linked list, but you are bragging about a class that has virtually no interface at all. While it may-be took you 20-30 minutes to write, trying to use it in practical programs will inevitably lead to hours of bug-chasing (unless someone takes a few hours and hides the mess behind a nice wrapper).
    Last edited by anon; 03-05-2008 at 05:22 PM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #64
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Hampton, VA
    what anon was hinting about private was this:

    In a hypothetical template linked-list class you would make your node struct private, and next (and previous pointers if applicable) private as well. typically the iterator class is part of the public interface. The whole point of the iterators are to provide the user with random access to the list. Lists should (as templates) should not provide any indexing features (like insert at position 6), that's what the iterators are for. The user should decide how they want to use the list, the creator of the list should only provide being able to get to that node by pointing to it through the use of iterators. This is the whole idea in OOP behind encapsulation and information hiding. Like anon or CornedBee (not sure who exactly) pointed out that they shouldn't have to manipulate next and prev pointers to iterate the list (hence the point of iterators).

    I don't want to put your effort down however, you know what you're doing, however your attempt simply fails to meet the requirements of a generic solution.
    Ubuntu Desktop
    Geany (for quick projects)
    Anjuta (for larger things)

  5. #65
    Registered User
    Join Date
    Jan 2005
    >> Buggy how? it compiles on my system just fine.
    What does successful compilation have to do with bugginess? There is one real bug that has already been mentioned.

  6. #66
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Since noone bothered ot point out the one really obvious bug (caused by a bad copy/past) I can only assume that noone bothered to even attempt to compile it.
    I did point out that it would not compile (at least from my visual inspection, which could be wrong), but I did not notice that you had corrected it soon after.

    The reason why I said this is not "templates versus code" is that my point is:
    However, it is much better and easier to use the interface of an existing container than implement such a container yourself.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  2. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  3. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM
  4. circular linked lists??
    By atif in forum C Programming
    Replies: 3
    Last Post: 04-30-2002, 03:58 AM
  5. circular shift
    By n00bcodezor in forum C Programming
    Replies: 2
    Last Post: 11-20-2001, 03:51 AM