Swaping - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: Swaping (/showthread.php?tid=1523) Pages:
1
2
|
Swaping - CSslymer - 03-05-2023 Môže nám niekto pomôcť. Mám problém s jedným algoritmom. Neviem to vyriešiť. Ide o triedenie čísel od najväčšieho po najmenšie. Predmet - Objekt - Strana - súradnice - súradnice - súradnice - súradnice - súradnice - súradnice Predmet - Objekt - Strana - súradnice - súradnice - súradnice Objekt - Strana - súradnice - súradnice - súradnice - súradnice - súradnice - súradnice Objekt - Strana - súradnice - súradnice - súradnice - súradnice - súradnice - súradnice Predmet - Objekt - Strana - súradnice - súradnice - súradnice Strana - súradnice - súradnice - súradnice Strana - súradnice - súradnice - súradnice Strana - súradnice - súradnice - súradnice Predmet - Objekt - Strana - súradnice - súradnice - súradnice - súradnice - súradnice - súradnice Každý predmet má niekoľko objektov. Každý objekt má niekoľko strán Každá strana má niekoľko súradníc. Čo sa môže zmeniť. Musím ich vytriediť. Vk = náhodné číslo Objekt(1, 1, 1, 0).z = Vk Objekt(1, 1, 1, 1).x = -Vk Objekt(1, 1, 1, 1).y = -Vk Objekt(1, 1, 4, 4).x = Vk Objekt(1, 1, 4, 4).y = -Vk Objekt(1, 1, 4, 4).z = Vk Objekt(2, 1, 2, 6).x = Vk Objekt(2, 1, 2, 6).y = Vk Objekt(2, 1, 2, 6).z = Vk Objekt ( 2 , 1 , 2 , 6 ) Predmet - Objekt - Strana - súradnice Počítal som súradnice a spočítal steny na obejct. Teraz mám Predmet a Objekt Skúsil som toto a nefunguje to veľmi dobre: SwapStran(i, a, b).z = SwapStran(i, a, b).z + Z SwapObjektov(i, a).z = SwapObjektov(i, a).z + SwapStran(i, a, b).z -- SwapSubjektov(i).z = SwapSubjektov(i).z + SwapObjektov(i, a).z toto už nie je možné pretože súčet rôznych predmetov je príliš veľký a nefunguje to -- SwapingStran: Pre i = 1 Do PocetSubjektov Ak PovolenieSwapObjektov(i) = 1 Potom Znovu = 0 Pre a = 1 To Subjekt(i).PocetObjektov Pre b = 1 To Subjekt(i).PocetStran k = 1: Ak b = Predmet(i).PocetStran Potom k = 0 Ak SwapStran(i, a, b).z > SwapStran(i, a, b + k).z Potom Swap SwapStran(i, a, b).z, SwapStran(i, a, b + k).z Znovu = 1 Koniec Ak Ďalej b Ďalej a Ak Znovu = 1, potom prejdite na SwapingStran: Koniec Ak Ďalej i SwapingObjektov: Pre i = 1 Do PocetSubjektov Ak PovolenieSwapObjektov(i) = 1 Potom Znovu = 0: O = 0: Ak i = PocetSubjektov Potom O = 1 Pre a = 1 To Subjekt(i).PocetObjektov k = 1: Ak a = Subjekt(i).PocetObjektov Potom k = 0 Ak SwapObjektov(i - O, a).z < SwapObjektov(i, a + k).z Potom Swap SwapObjektov(i - O, a).z, SwapObjektov(i, a + k).z Znovu = 1 Koniec Ak Ďalej a Koniec Ak Ďalej i If Znovu = 1 Then GoTo SwapingObjektov -------------------------------------------------- ------------------------------------- Tu je problém: Výmena Subjektov: Znovu = 0: ii = 0: a1 = 1: a = 0 Pre i = 1 Do PocetSubjektov ii = ii + 1 Ak i + ii >= PocetSubjektov Potom ii = 0: Znovu = 0 Ak PovolenieSwapObjektov(i) = 1 alebo PovolenieSwapObjektov(i + ii) = 1 Potom Do a = a + 1 Ak SwapObjektov(i, a).z < SwapObjektov(i + ii, a1).z Potom Swap SwapObjektov(i, a).z, SwapObjektov(i + ii, a1).z Znovu = 1 Koniec Ak Ak a >= Predmet(i).PocetObjektov Potom a = 0 a1 = a1 + 1 Koniec Ak Ak a1 >= Subjekt(i + ii).PocetObjektov Then a1 = 1: Exit Do Slučka, kým znovu = 1 Koniec Ak Ďalej i If Znovu = 1 Then GoTo SwapingSubjektov RE: Swaping - mnrvovrfc - 03-05-2023 Hi slymer Is it possible for you to redo this post in English? A very small amount was actually translated in source code. Otherwise I could try to paste this into the QB64 IDE changing "Koniec Ak" into "END IF" for example but it would be laborious. What do you want to do with "SWAP" command? RE: Swaping - vince - 03-05-2023 (03-05-2023, 05:06 PM)CSslymer Wrote: Každý predmet má niekoľko objektov. wow PE has come a long way RE: Swaping - Petr - 03-05-2023 @mnrvovrfc He wants advice on sorting numbers from largest to smallest - in a four-dimensional array. RE: Swaping - Petr - 03-05-2023 Can someone help us. I have a problem with one algorithm. I can't solve it. It is about sorting the numbers from largest to smallest. Subject - Object - Page - coordinates - coordinates - coordinates - coordinates - coordinates - coordinates Subject - Object - Page - coordinates - coordinates - coordinates Object - Page - coordinates - coordinates - coordinates - coordinates - coordinates - coordinates Object - Page - coordinates - coordinates - coordinates - coordinates - coordinates - coordinates Subject - Object - Page - coordinates - coordinates - coordinates Side - coordinates - coordinates - coordinates Side - coordinates - coordinates - coordinates Side - coordinates - coordinates - coordinates Subject - Object - Page - coordinates - coordinates - coordinates - coordinates - coordinates - coordinates Each object has several objects. Each object has several sides Each side has several coordinates. What can change. I have to sort them out. Vk = random number Object(1, 1, 1, 0).z = Vk Object(1, 1, 1, 1).x = -Vk Object(1, 1, 1, 1).y = -Vk Object(1, 1, 4, 4).x = Vk Object(1, 1, 4, 4).y = -Vk Object(1, 1, 4, 4).z = Vk Object(2, 1, 2, 6).x = Vk Object(2, 1, 2, 6).y = Vk Object(2, 1, 2, 6).z = Vk Object ( 2 , 1 , 2 , 6 ) Subject - Object - Page - coordinates I calculated the coordinates and counted the walls on the perimeter. Now I have a Subject and an Object I tried this and it doesn't work very well: SwapPage(i, a, b).z = SwapPage(i, a, b).z + Z SwapObjects(i, a).z = SwapObjects(i, a).z + SwapPages(i, a, b).z -- SwapSubjects(i).z = SwapSubjects(i).z + SwapObjects(i, a).z this is no longer possible because the sum of different items is too big and it doesn't work -- SwappingPage: For i = 1 To Number of Subjects If EnableSwapObject(s) = 1 Then = 0 again For a = 1 To Subject(s).Number of Objects For b = 1 To Subject(s). Number of Pages k = 1: If b = Subject(s).NumberPages Then k = 0 If SwapPage(i, a, b).z > SwapPage(i, a, b + k).z Then Swap SwapPage(i, a, b).z, SwapPage(i, a, b + k).z Again = 1 End If Further b Further a If Again = 1, then go to SwappingPage: End If Further i SwappingObjects: For i = 1 To Number of Subjects If EnableSwapObject(s) = 1 Then Again = 0: O = 0: If i = Number of Subjects Then O = 1 For a = 1 To Subject(s).Number of Objects k = 1: If a = Subject(s).Number of Objects Then k = 0 If SwapObjects(i - O, a).z < SwapObjects(i, a + k).z Then Swap SwapObjects(i - O, a).z, SwapObjects(i, a + k).z Again = 1 End If Further a End If Further i If Again = 1 Then GoTo SwappingObjects -------------------------------------------------- ------------------------------------- Here's the problem: Exchange of Subjects: Again = 0: ii = 0: a1 = 1: a = 0 For i = 1 To Number of Subjects ii = ii + 1 If i + ii >= Number of Subjects Then ii = 0: Again = 0 If EnableSwapObjects(i) = 1 or EnableSwapObjects(i + ii) = 1 Then To a = a + 1 If SwapObjects(i, a).z < SwapObjects(i + ii, a1).z Then Swap SwapObjects(i, a).z, SwapObjects(i + ii, a1).z Again = 1 End If If a >= Object(s).CountObjects Then a = 0 a1 = a1 + 1 End If If a1 >= Subject(i + ii).Number of Objects Then a1 = 1: Exit Do Loop until again = 1 End If Further i If Again = 1 Then GoTo SwappingSubjects RE: Swaping - Petr - 03-05-2023 This is the principle of sorting numbers in a one-dimensional array as I use it. There are better procedures, but hopefully this will help. Code: (Select All) 'vygeneruju nahodna cisla RE: Swaping - bplus - 03-05-2023 I'm confused. Is there 1 value for every (x, y, z) ie v = f(x, y, z) to sort, like a color for every x, y, z in 3D graphic Or is there 1 value for every (x, y, z, t) ie v = f(x, y, z, t) to sort? like getting a pixel color in 3D movie at x, y, z and at a point in time as well! Or something else all together??? Update: Oh it looks as if there is (x, y, z) at end of array inside an array inside an array inside an array, yikes! What / where is the value we are sorting? This looks too confused to mess with.... RE: Swaping - mnrvovrfc - 03-05-2023 Three-dimensional pages? But there's also object and subject. If the four dimensions don't create a really big array, then it might be better to create an array of strings, first storing the (x,y,z) values in serialized form, and then the four dimensions in turn, also in serialized form. Then it becomes easier to sort by the (x,y,z) values. But then the author would have to decide if he/she wants to order by x, y or z. For example: Object(1, 2, 3, 4).x = 2 Object(1, 2, 3, 4).y = 3 Object(1, 2, 3, 4).z = 4 could be turned into this: Code: (Select All) 004z002x003y001002003004 as a string entry. Put the value first then the field's name to make it easier to sort numerically, and keep the field names in the same order throughout. (Actually the field names serve only for documentation.) Of course, if the value required is greater than 999 then add more zeroes to match the length. If negative values are also required then also add plus or minus sign. There could be other variations about ordering the string value, but this is only to sort the contents. Then how to put it back into the four-dimensional array... I guess figure out the extents for each dimension and walk sequentially through the string array setting the values. (shrugs) This example would require good string-parsing routines, instead of the mountains of "FOR... NEXT" and "IF... THEN... END IF" revealed in the code of the first post. This is only for Objects() array. Now I notice SwapPages(), SwapSubjects(), SwapObjects() which would each need its own special treatment. RE: Swaping - CSslymer - 03-06-2023 (03-05-2023, 06:43 PM)bplus Wrote: Som zmätený. ide o vykresľovanie grafiky. ako prvý sa zobrazí najvzdialenejší objekt s najväčším číslom . a tak ďalej. táto hodnota je z výpočet súradníc jednej strany objektu. potom celý objekt. a porovnáva sa s objektmi v celom systéme. RE: Swaping - vince - 03-06-2023 fuj, bplus zmateny! |