Thread: Is Sedgewick's a good book to follow?

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    57

    Question Is Sedgewick's a good book to follow?

    I am sorry, if this is a wrong question in this forum.

    It has been quite a while since I have coded in C and last week, I decided to finish atleast one Algo book cover to cover(or atleast try), thus revising C. I picked up Sedgewick on the advice of a few friends and also ACCU review.

    But is the book really good? Does the code in it work?

    I tried running a few and already there are so many errors. I started with the 4th chapter and the code on Josephes election, reversing the list etc are already not working. Infact in solving Josephes election problem using a circular list, I rubbed my eyes when I saw

    N--

    right at the end of the code, which was there for I dont know why.

    Never mind the silly naming style of the variables. Any opinions?

    Thanks and I am sorry again if it was not the right forum.

    Anoop.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >But is the book really good?
    Yes, it is.

    >Does the code in it work?
    No. Sedgewick is a believer in reusing previous work, so most of the code is a poor Pascal to C conversion. If you want solid algorithms to write code from then I suggest Knuth's texts. Sedgewick gives excellent explanations, but his C code is just awful most of the time.

    >which was there for I dont know why
    I think you read the code wrong. My copy shows "N--;" inside of the last loop:
    Code:
    while (x != x->next)
      {
        for (i = 1; i < M; i++) x = x->next;
        x->next = x->next->next; N--;
      }
    printf("%d\n", x->item);
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    57
    >I think you read the code wrong. My copy shows "N--;" inside of the last loop:

    Precisely. I am also refering to the same statement. I am unable to comprehend the need for N--;

    Anoop.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I am unable to comprehend the need for N--;
    Oh, I see. There is none, you can safely remove it. If N were used later for the number of items then decrementing it would make sense. But as it stands, there's no point.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is this book <JAVA in a netshell> good for C++ programmers?
    By meili100 in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-28-2008, 02:28 AM
  2. A good C++ Reference book
    By tiachopvutru in forum C++ Programming
    Replies: 5
    Last Post: 05-13-2008, 04:47 PM
  3. Good vectors/planes book
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-19-2005, 02:43 PM
  4. I'm looking for a good book on 3D game programming
    By Music_Man in forum Game Programming
    Replies: 2
    Last Post: 09-09-2001, 09:29 PM