Understanding Circus Tower problem solution

Hi,

Could you please help me understand this solution to the problem.

A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute the largest possible number of people in such a tower.

EXAMPLE:
Input:
(ht, wt): (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110)
Output: The longest tower is length 6 and includes from top to bottom:
(56, 90) (60,95) (65,100) (68,110) (70,150) (75,190)

My question is, how can fillNextSeq generate new sequences, if it doesn’t consider startFrom.

============================

public class Question {
ArrayList items;
ArrayList lastFoundSeq;
ArrayList maxSeq;

/ Returns longer sequence
ArrayList seqWithMaxLength(ArrayList seq1, ArrayList seq2) {
return seq1.size() > seq2.size() ? seq1 : seq2;
}

// Fills next seq w decreased wts&returns index of 1st unfit item.
int fillNextSeq(int startFrom, ArrayList seq) {
int firstUnfitItem = startFrom;
if (startFrom < items.size()) {
for (int i = 0; i < items.size(); i++) {
HtWt item = items.get(i);
if (i == 0 || items.get(i-1).isBefore(item)) {
seq.add(item);
} else {
firstUnfitItem = i;
}
}
}
return firstUnfitItem;
}

// Find the maximum length sequence
void findMaxSeq() {
Collections.sort(items);
int currentUnfit = 0;
while (currentUnfit < items.size()) {
ArrayList nextSeq = new ArrayList();
int nextUnfit = fillNextSeq(currentUnfit, nextSeq);
maxSeq = seqWithMaxLength(maxSeq, nextSeq);
if (nextUnfit == currentUnfit)
break;
else
currentUnfit = nextUnfit;
}
}

what exactly are you asking?

  • if the above code solves the question? (if so, then it is a “C” question, not an Xojo one)
  • or , "Hey I have this “C” code, can someone help translate it to Xojo?

Hi,

Yes. I am interested in “if the above code solves the question? (”. If so, How ? I am sorry, I am new to Xojo. When should I write to Xojo ? Can this question be reclassified into “C” question ?

Since the is not a “C” forum, you would only get an answer here, if the question interested someone on the forum that had a “C” background, and was bored…

Hmm, how can I tag this in “C” forum ?

Xojo IS NOT “C”… Xojo is a language all of its own, I suggest you might try “StackOverflow” or find a “C” oriented forum, but this is not one of them

oops sorry, I was redirected to here by someone.

Good luck with your homework :wink: