[comp.lang.pascal] Linked Lists vs Boolean Check

clong@remus.rutgers.edu (Chris Long) (09/26/90)

I'm writing some code which involves maximizing a function
over a variety of "objects" (i.e. records).  There are about
5 classes of objects, we have about 1000 of each class of which
I want to use about 8.   Now I have a sequence of classes which
wants to be maximized, and no duplication is allowed.  As an
example, let's say we have two classes, c1 and c2, then one
small scenerio could be to find the maximum of f(a,b,c,d) such
that a,d \in c2, b,c \c1 and a<>d, b<>c.  Essentially all
different possibilities (for a fixed order sequence of classes)
must be checked (I do some fancy pruning, but don't worry about
that).  Pseudocode for the above example might be

for a:=1 to 1000
  mark a used in X
  for b:=1 to 1000
    mark b used in Y
    for c:=1 to 1000
      if c not used in Y
        for d:=1 to 1000
          if d not used in X
             { compute }
         end
      end
      unmark b in Y
    end
    unmark a in X
end.

Here's my question.  I currently have 40 nested while .. do
loops, and as the condition for each while .. do I have a boolean
check to avoid duplication.  Would it be faster instead to
have each class set up as a linked list?  I wouldn't have any
checking to do, just move on to the next item.  However, there
is the overhead of adding and deleting elements.  Any guesses?
Is it worth my time to actually try this experiment, or are linked
lists an obviously bad idea?  Any way better than both?

Comments greatly appreciated.

-Chris