Help with an algorithm...

dunbarx at aol.com dunbarx at aol.com
Mon Aug 5 13:40:36 EDT 2019


Hi.
This seems like a good case for arrays (pseudo):
You have to create an array for each parent. The only way i see to find those is to go through the list looking for lines that DO NOT start with a space. If you work from the bottom up, since children are always at the bottom and they always have spaces in front, you can find the lastMost parent.
Set the itemDel to that parent, and isolate the last item. This will be a list of children of that parent.
See if there is a corresponding parent in the new list, and isolate that "item" list of children.
Run through the children of the old list and see if they live in the new list. If they do, add them:The array part is something like:
put oldChildren & return & newChildren into allChildrenrepeat for each line tLine in allChildrenput tLine into myArray[tLine]

Delete the last item of the old list and do it again. This way the last item can be isolated directly.
Craig

-----Original Message-----
From: Paul Dupuis via use-livecode <use-livecode at lists.runrev.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Cc: Paul Dupuis <paul at researchware.com>
Sent: Mon, Aug 5, 2019 11:53 am
Subject: Help with an algorithm...

Today is not my coding day. I have a problem I should be able to design 
a solution for an am struggling. Clearly I am missing "something"

I have 2 lists (LISTNEW and LISTOLD) of the following format:

ParentA
<space>Child 1
<space>Child 2
<space>etc.
ParentB
<space>Child 1
<space>etc.
etc.

The parents are in alphabetical sorted order, the children may not be in 
sorted order

I need to hunt through LISTOLD comparing the LISTOLD Parents to the 
LISTNEW Parents
   FOR any LISTOLD Parent present in LISTNEW, check the Children of the 
matching Parents and add any Child for the LISTOLD Parent that is not 
already under its matching LISTNEW Parent
   FOR any LISTOLD Parent NOT in LISTNEW, I can ignore the Parent and 
its Children

I can not seem to write an approach to solve this today. Does any body 
have some code so solve this they may be willing to share?

_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


More information about the Use-livecode mailing list