#include
#include
#include
#define ARRAYSIZE 100
#define true 1
#define false 0
int main()
{
int maxlen=0;
int a,i,j;
int updated;
int value;
int lisArray[ARRAYSIZE][ARRAYSIZE];
/* Seed random number generator */
srand((long)time(NULL));
/* Create 100 random number from 0 to 1000 */
for (a=0; a < 100; a++) {
value = rand() % 1000;
printf("Value: %d\n", value);
/* if first value, just place it in LIS(1) */
if (maxlen == 0) {
lisArray[0][0] = value;
maxlen +=1;
}
else {
updated = FALSE;
i = 0;
do {
/* Check if new value is less than the max of this array */
if (value < lisArray[i][i]) {
if (i > 0) {
/* Copy only different elements from "one shorter" array */
j = i-1;
while (lisArray[i][j] != lisArray[i-1][j] && j >= 0) {
lisArray[i][j] = lisArray[i-1][j];
j--;
}
}
/* Set new "last" value */
lisArray[i][i] = value;
/* Don't need to check anymore arrays... */
updated = TRUE;
}
i++;
} while (i < maxlen && !updated);
/* Check if value is still larger than greatest value of longest array */
if (!updated) {
/* Copy "one-smaller array" into this on (except last) */
for (j=0; j
lisArray[i][j] = lisArray[i-1][j];
}
/* Append new value to end */
lisArray[i][i] = value;
maxlen += 1;
}
}
}
/* Print out the arrays */
for (i=0; i < maxlen; i++) {
for (j=0; j< (i+1); j++) {
printf("%d ", lisArray[i][j]);
}
printf("\n");
}
}