codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

php strtotime array sorting issue


By : , Category : php

Change 'next sunday' to 'sunday', put it in as the first array element and you should be good..

ReLated :

Try do not sum 1 in the loop for:

for(int i = left; i < right; i++)
{
...

If not, try to adapt this code to yours. I am sorting by increasing distances instead of alphabetically:

public static void ordenarChollos(List<CholloObjeto> chollostemp, int izq, int der) {
    CholloObjeto pivote=chollostemp.get(izq); 
    int i=izq; 
    int j=der; 
    CholloObjeto aux;

    while(i<j){           
        while(chollostemp.get(i).getDistance() <= pivote.getDistance() && i<j) i++; 
        while(chollostemp.get(j).getDistance() > pivote.getDistance()) j--;         
        if (i<j) {                      
            aux = chollostemp.get(i);                 
            chollostemp.set(i,chollostemp.get(j));
            chollostemp.set(j,aux);
        }
    }
    chollostemp.set(izq,chollostemp.get(j)); 
    chollostemp.set(j,pivote); 
    if(izq<j-1)
        ordenarChollos(chollostemp,izq,j-1); 
    if(j+1 <der)
        ordenarChollos(chollostemp,j+1,der); 
}

The problem with your approach is most likely that you're comparing Doubles with ==. In most cases new Double(x) == new Double(x) is false since == tests for object equalitiy. You'd have to use equals() here (or unbox yourself).

Just a small hint: you might want to use the compareTo methods of the primitive wrappers, e.g. like this:

public int compareTo(ITSVehicle v) {
  result = this.getCapacity(0).compareTo(v.getCapacity(0));
  if( result == 0 ) {
    result = this.getCapacity(1).compareTo(v.getCapacity(1));
  }
  if( result == 0 ) {
    result = this.getCapacity(2).compareTo(v.getCapacity(2));
  }

  return result;
}

Just note that this would break if any capacity was null, but that would be the case with your approach as well (and the exception there would be harder to track since the auto(un)boxing would throw the NPE).

If they can't be null you might want to consider using primitives instead. Your data already implies that the capacities have different meanings and thus from a design point of view it might be good not to store them in a list etc. (which you do, I assume, and which thus would require you to use Double instead of double).

You shouldn't need to do what you're doing. You have a Client object already in the mClients array. So just sort that directly, instead of splitting it into 7 arrays and sorting the arrays.

 List<Client> sortedClients = mClients.OrderBy(a => a.LastName)
                                      .ThenBy(b => b.FirstName)
                                      .ToList();

Use DateTime. It's much better for date math.

$tomorrow = new DateTime('tomorrow');
$now = new DateTime();
$diff = $tomorrow->diff($now);
echo $diff->format("%h hours, %i minutes, %s seconds");
// 7 hours, 12 minutes, 53 seconds

See in action

Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .