473,472 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

sortign string - why this difference?

Hi!

I have 2 arrays which I sort ny the first one.

for($i=0;$i<(count($item1)-1);$i++)
{
$k = $i;
for($j=$i;$j<(count($item1)-1);$j++);
{
if (strcmp($item1[$k],$item1[$j])<0)
$k = $j;
}
if($k<>$i)
{
$temp=$item1[$i]; $item1[$i]=$item1[$k];
$item1[$k]=$temp;
$temp=$item2[$i]; $item2[$i]=$item2[$k];
$item2[$k]=$temp;
}
}

Pretty simple - it works, I get the highest item first - I'd like it
the other way.

But
if (strcmp($item1[$j],$item1[$k])<0) // k an j switched
does not work, though
if (strcmp($item1[$j],$item1[$k])>0) // < replaced by >
does work, but it is descending

why this?

I can read my array backwards, it is ok, but why this????

BR
Sonnich

Jun 15 '06 #1
3 1206

Sonnich wrote:
Hi!

I have 2 arrays which I sort ny the first one.

for($i=0;$i<(count($item1)-1);$i++)
{
$k = $i;
for($j=$i;$j<(count($item1)-1);$j++);
{
if (strcmp($item1[$k],$item1[$j])<0)
$k = $j;
}
if($k<>$i)
{
$temp=$item1[$i]; $item1[$i]=$item1[$k];
$item1[$k]=$temp;
$temp=$item2[$i]; $item2[$i]=$item2[$k];
$item2[$k]=$temp;
}
}

Pretty simple - it works, I get the highest item first - I'd like it
the other way.

But
if (strcmp($item1[$j],$item1[$k])<0) // k an j switched
does not work, though
if (strcmp($item1[$j],$item1[$k])>0) // < replaced by >
does work, but it is descending

why this?

I can read my array backwards, it is ok, but why this????

BR
Sonnich


I should add the the strings I have are something like:

AB123456
BB345324
BB235342
XX3634543
T44444 <- this is rare, but might happen
TR000001

Sonnich

Jun 15 '06 #2
Sonnich,

Most likelly your an error here:
for($j=$i;$j<(count($item1)-1);$j++);
This "for" is an empty "for" that just does nothing, because its body
is empty--it is closed by the the last ";" in the line.

--
Alexander,
http://www.alexatnet.com/

Jun 15 '06 #3

AlexVN wrote:
Sonnich,

Most likelly your an error here:
for($j=$i;$j<(count($item1)-1);$j++);
This "for" is an empty "for" that just does nothing, because its body
is empty--it is closed by the the last ";" in the line.


stupid me.... thanks

Sonnich

Jun 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Dan Bass | last post by:
which one do you use and why? MyString == null || MyString == "" vs MyString == null || MyString.Length == 0
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
12
by: Tee | last post by:
String Builder & String, what's the difference. and when to use which ? Thanks.
35
by: Cor | last post by:
Hallo, I have promised Jay B yesterday to do some tests. The subject was a string evaluation that Jon had send in. Jay B was in doubt what was better because there was a discussion in the C#...
15
by: roberts.noah | last post by:
Are there any decent benchmarks of the difference between using c strings and std::string out there? Google isn't being friendly about it. Obviously this would be dependant on different...
6
by: Charlie | last post by:
Hi: Is there any difference between string.Empty and String.Empty? And what is the benefit of using it over "". Thanks, Charlie
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
7
by: Bruce One | last post by:
What is the difference between String and string in C#? What can u do with string that you cant do with String, vice versa?
6
by: JonathanOrlev | last post by:
Hello everyone, I have a newbe question: In Access (2003) VBA, what is the difference between a Module and a Class Module in the VBA development environment? If I remember correctly, new...
6
by: =?Utf-8?B?SmVmZg==?= | last post by:
I thought this would already be covered here, but my search turned up nothing. In VS2005, if I use "String" to define a new variable/class, it colors it in the Aqua color as it does other...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.