Circular Lists

This is a discussion on Circular Lists within the C++ Programming forums, part of the General Programming Boards category; You haven't beat the challenge. You implemented a buggy and effectively unusable linked list. The challenge was to beat my ...

  1. #61
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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!
    CornedBee

    "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
    Posts
    3,189
    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 04:03 PM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  3. #63
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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 04: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
    Location
    Hampton, VA
    Posts
    391
    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
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  5. #65
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    >> 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
    Location
    Singapore
    Posts
    21,794
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 5 of 5 FirstFirst 12345
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, 02:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21