What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Coding: swapping items in a row

Coding: swapping items in a row
Author: Message:
KeyStorm
Elite Member
*****

Avatar
Inn-sewer-ants-pollie-sea

Posts: 2156
Reputation: 45
38 / Male / –
Joined: Jan 2003
O.P. Coding: swapping items in a row
A challenging logic test for all you coders out there:

I need for the next version of KSMAS a system to be able to swap images.
For every image there is a list of other available slots either filled or not with which to swap current image (/item).

Now I need a system (probably recursive) to swap all files as the user wants and troubleshoot any weird combination (more than one pointing to a slot, etc.).

So we have an array of images:
12345

and if we want to swap item 2 with item 5, the returned swap-array would be:
15345

and that would set up the images-array as follows:

15342

got my point? Good!

It's possible that it's rather simple, but I'm stuck atm.

So, please, help me if you have any clue.

Thanks. :)

This post was edited on 07-11-2004 at 06:26 PM by KeyStorm.
07-11-2004 06:25 PM
Profile E-Mail PM Web Find Quote Report
fluffy_lobster
Veteran Member
*****

Avatar
Posts: -2

Posts: 1391
Reputation: 23
36 / Male / Flag
Joined: Nov 2002
RE: Coding: swapping items in a row
code:
function swap($arr,$key1,$key2)
{
$foo = $arr[$key1];
$arr[$key1] = $arr[$key2];
$arr[$key2] = $foo;

return $arr;
}

That's how I'd do it... I'd say that's fairly simple too.
07-11-2004 06:30 PM
Profile E-Mail PM Web Find Quote Report
KeyStorm
Elite Member
*****

Avatar
Inn-sewer-ants-pollie-sea

Posts: 2156
Reputation: 45
38 / Male / –
Joined: Jan 2003
O.P. RE: Coding: swapping items in a row
Yeah, well.
That's obviously the simple way to swap 2 items, but problems appear when for example:

1- We have a "bouncing-swap" where the target item should be swapped with a third one and so on. E.g. swap 2 with 5 and 5 with 3.

2- We have several swaps targeting the same slot: swapping 2 with 5, 4 with 5 and 1 with 5, what would mean: swap 2 with 5,  5 with 4 and 4 with 1 (back to problem nr. 1).

Tbh, Lobster, I could've done that, I'm not that n00b, you know ;)
07-11-2004 08:48 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On