Search:

Type: Posts; User: laserlight

Page 1 of 20 1 2 3 4

Search: Search took 0.14 seconds.

  1. Replies
    34
    Views
    277

    Oh, I missed this: It isn't because the inner...

    Oh, I missed this:

    It isn't because the inner loop always loops in successively smaller iterations, whereas you can terminate the inner loop at the point of the last swap in the previous...
  2. Use another static local variable to record the...

    Use another static local variable to record the previous value of x. If x differs from this static local, then you know that it is time to reset exponent.
  3. Replies
    34
    Views
    277

    As in Zeus_'s post #10? That's a bubble sort. It...

    As in Zeus_'s post #10? That's a bubble sort. It is equivalent to the Wikipedia bubble sort article's "Optimizing bubble sort" first example pseudocode, except that instead of just decrementing Size...
  4. Replies
    34
    Views
    277

    This definitely looks like a better candidate for...

    This definitely looks like a better candidate for a bubble sort, and it looks like it was taken directly (with expansion of the swap function/macro) from your "Bubble sort misconceptions" link under...
  5. A tale of two sorts: classifying an inefficient sorting algorithm

    This thread has branched off from wufflz's Bubblesorting Array elements in order to avoid going too far off track for that discussion. It makes reference to Owen Astrachan's Bubble Sort: An...
  6. Replies
    34
    Views
    277

    This is not a bubble sort as it does not always...

    This is not a bubble sort as it does not always swap adjacent elements:

    I guess that's why you call it "dodgy bubble sort", but isn't that just misleading?
  7. That's also a linked list that prepends to the...

    That's also a linked list that prepends to the head, which is not what I'm talking about, unless you want to invert it and say to enqueue to prepend to the head, and to dequeue is to retrieve and...
  8. Replies
    34
    Views
    277

    They don't: this one doesn't always swap adjacent...

    They don't: this one doesn't always swap adjacent elements. Perhaps you missed:

    So, if you agree that terminating early is an optimisation for bubble sort, then it follows that terminating early...
  9. You just need a linked list for which you keep...

    You just need a linked list for which you keep track of both the head and the tail. To enqueue is to append a new node at the tail; to dequeue is to retrieve and remove the node at the head.
  10. Replies
    34
    Views
    277

    Eh, I'm really curious who has been going around...

    Eh, I'm really curious who has been going around teaching students to implement a bubble sort that doesn't stop when no more swaps are performed.
  11. Replies
    6
    Views
    103

    Exactly. atoi suffers from the same design flaw,...

    Exactly. atoi suffers from the same design flaw, which is why strtol is usually recommended as an alternative. strtol switches things around a bit to have the output be a return value and the error...
  12. Replies
    6
    Views
    103

    My question would then be: why is this...

    My question would then be: why is this util_get_string_int when it cannot handle negative number input as would be expected for int? Perhaps it should have been util_get_string_unsigned_int, in which...
  13. Replies
    1
    Views
    87

    This cannot be done purely in standard C, so it...

    This cannot be done purely in standard C, so it would be helpful to know what relevant libraries your teacher has taught or recommended that you use for this exercise.
  14. Replies
    3
    Views
    112

    You might want to read these two technical...

    You might want to read these two technical dictionary entries for abstract data type and data structure. What you have in mind is the former, but when expressed in code we get the latter, which does...
  15. Replies
    12
    Views
    115

    It has to destroy the elements too, though in...

    It has to destroy the elements too, though in this case for int it isn't really relevant.


    And avoided the possibility of running into an assert on some implementation, methinks :p

    ...
  16. Replies
    8
    Views
    175

    You can use #define in a header; it is commonly...

    You can use #define in a header; it is commonly used to define named constants.

    Basically, if you have a header "other.h" that consists entirely of this:

    #define PI 3.1415
    And a "main.c" that...
  17. Replies
    8
    Views
    175

    That looks fine. Is this really the code that you...

    That looks fine. Is this really the code that you compiled? Is there anything that you left out or which isn't the same as what you compiled?
  18. That's because I had in mind comparing with...

    That's because I had in mind comparing with strlen: it would be easier to see that way since you can name the variable so the reader knows why it is compared to strlen. But if you're comparing with...
  19. You should be using strcspn instead of strspn,...

    You should be using strcspn instead of strspn, and you should be calling it separately in order to compare it with strlen, i.e., if the span that doesn't contain the invalid characters is equal to...
  20. Replies
    4
    Views
    138

    The "STL" stands for the "Standard Template...

    The "STL" stands for the "Standard Template Library", which is a collection of class templates and function templates providing generic algorithms, containers, and other connecting generic components...
  21. Replies
    2
    Views
    109

    I think fabi.mueller solved the problem...

    I think fabi.mueller solved the problem independently then removed the code.
  22. Replies
    6
    Views
    116

    For older versions of GCC, you might have to...

    For older versions of GCC, you might have to explicitly compile as C++11 with -std=c++11

    Well, at least I think this is a C++11 feature; if it was introduced in C++14 then you might be stuck, and...
  23. Replies
    6
    Views
    116

    You can do that: it sets the default member...

    You can do that: it sets the default member initialiser, although the initialisation itself is only done when the constructor is invoked, i.e., when the initialiser list would be run.
  24. Yes, it makes sense when you're dealing with...

    Yes, it makes sense when you're dealing with indices, though you have to be careful if you're looping from N-1 to 0 rather than the usual 0 to N-1.
  25. Replies
    1
    Views
    86

    It may be easier if you move your original...

    It may be easier if you move your original working code into a function, then call the function from main within the do while loop.
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4