473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Partial Sort ?

if I have an array of ten items how can I sort the first five items in
the array without sorting the second five items?
Jun 20 '07 #1
4 1874
Message-ID: <7i********************************@4ax.comfrom comatose
contained the following:
>if I have an array of ten items how can I sort the first five items in
the array without sorting the second five items?
Use a loop to copy first five to a temporary array, sort that array and
then replace into original using array_splice()
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 20 '07 #2
comatose wrote:
if I have an array of ten items how can I sort the first five items in
the array without sorting the second five items?
By using an user-defined sorting function.

See http://php.net/usort

You'll need to do some dirty tricks in that function to keep track of how
many items you have sorted, to not sort those, but that should be the way..

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
Jun 20 '07 #3
In our last episode, <7i********************************@4ax.com>, the
lovely and talented comatose broadcast on comp.lang.php:
if I have an array of ten items how can I sort the first five items in
the array without sorting the second five items?

Try searching the function index of manual for 'array' --- I'm pretty sure
you will find some useful slices of information to splice into your
knowledge base.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 580 days to go.
Owing to googlegroups not screening users to eliminate spammers and other
USENET abusers, I do not see most posts from googlegroups.
Jun 20 '07 #4
On Jun 20, 3:18 am, comatose wrote:
if I have an array of ten items how can I sort the first five items in
the array without sorting the second five items?
$array = array('c', 'b', 'a', 'q', 's', 'r', 'h', 'p');
$head = array_slice($array, 0, 5);
sort($head);
$newArray = array_merge($head, array_splice($array, 5));

I believe someone mentioned this...

Jun 20 '07 #5

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

Similar topics

7
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
5
by: __PPS__ | last post by:
Hello, I want to write specialized method for a class: template<class A, class B> class xxx{ A a; B b; operator bool()const{ a==b; } };
7
by: Lasse Vĺgsćther Karlsen | last post by:
I have a list of items and a "rule" for ordering them. Unfortunately, the rule is not complete so it won't define the correct order for any two items in that list. In other words, if I pick...
9
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. ...
16
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
10
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and...
9
by: Neal Barney | last post by:
I have a C program which runs on a device using a Zilog Z180 microprocessor. While it can address 1MB of RAM, it can only address 64KB at any given time. And of that only 16KB can be used for...
0
by: Dr. Peer Griebel | last post by:
I'm currently writing a small toy application to support symbolic algebra. Therefore I implemented some classes Term, Var, Number, Sum, Product, Power. These classes are tightly coupled. So it...
0
by: arturbl | last post by:
I just finished my sort of MVC/P framework where I do url rewriting. During the url rewriting I access properties of the controller/presenter based on the url. First thing that most of us would...
10
by: JDeats | last post by:
So I have a class that spans over two partial classes in code, here's an example (do not read much into this, the code is of no practical use, this is just a simple example of where my confusion...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.