Search Results

Search found 9186 results on 368 pages for 'sort'.

Page 3/368 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • MySQL Hibernate sort on 2 columns

    - by sammichy
    I have a table as follows Table item { ID - Primary Key content - String published_date - When the content was published create_date - When this database entry was created } Every hour (or specified time interval) I run a process to update this table with data from different sources (websites). I want to display the results according to the following rules. 1. The entries created each time the process runs should be grouped together. So the entries from the 2nd process run will always be after the entries from the first process run even if the published_date of an entry from the first run is after the published_date of an entry from the 2nd run. 2. Within the grouping by run, the entries by sorted by published_date 3. Another restriction is that I prefer that data from the same source not be grouped together. If I do the sort by create_date, published_date I will end up with data from source a, data from source b etc. I prefer that the data within each hour be mixed up for better presentation If I add a column to this table and store a counter which increments each time the process is run, it is possible to create a query to sort first by counter and then by published_dt. Is there a way to do it without adding a field? I'm using Hibernate over MySQL. e.g. Hour 1 (run 1) 4 rows collected from site a (rows 1-4) 3 rows collected from site b (rows 5-7) hour 2 (run 2) 2 row collected from site a (rows 8-9) 3 rows collected from site b (rows 10-12) ... After each run, new records are added to the database from each website. The create date is the time when the record was created in the database. The published date is part of the content and is read in from the external source. When the results are displayed I would like rows to be grouped together based on the hour they were published in. So rows 1-7 would be displayed before rows 8-12. Within each hourly grouping, I would like to sort the results by published date (timestamp). This is necessary so that the posts from all the sites collected in that hour are not grouped together but rather mixed in with each other.

    Read the article

  • Sort ArrayList alphabetically

    - by relyt
    I'm trying to find all permutations of a string and sort them alphabetically. This is what I have so far: public class permutations { public static void main(String args[]) { Scanner s = new Scanner(System.in); System.out.print("Enter String: "); String chars = s.next(); findPerms("", chars); } public static void findPerms(String mystr, String chars) { List<String> permsList = new ArrayList<String>(); if (chars.length() <= 1) permsList.add(mystr + chars); //System.out.print(mystr + chars + " "); else for (int i = 0; i < chars.length(); i++) { String newString = chars.substring(0, i) + chars.substring(i + 1); findPerms(mystr + chars.charAt(i), newString); } Collections.sort(permsList); for(int i=0; i<permsList.size(); i++) { System.out.print(permsList.get(i) + " "); } } } IF I enter a string "toys" I get: toys tosy tyos tyso tsoy tsyo otys otsy oyts oyst osty osyt ytos ytso yots yost ysto ysot stoy styo soty soyt syto syot What am I doing wrong. How can I get them in alphabetical order? Thanks!

    Read the article

  • Java Bucket Sort on Strings

    - by Michael
    I can't figure out what would be the best way to use Bucket Sort to sort a list of strings that will always be the same length. An algorithm would look like this: For the last character position down to the first: For each word in the list: Place the word into the appropriate bucket by current character For each of the 26 buckets(arraylists) Copy every word back to the list I'm writing in java and I'm using an arraylist for the main list that stores the unsorted strings. The strings will be five characters long each. This is what I started. It just abrubdly stops within the second for loop because I don't know what to do next or if I did the first part right. ArrayList<String> count = new ArrayList<String>(26); for (int i = wordlen; i > 0; i--) { for (int j = 0; i < myList.size(); i++) myList.get(j).charAt(i) } Thanks in advanced.

    Read the article

  • CUSTOM SORT XSL ?

    - by Nanda
    Hi This is my XML Structure like this input :- <MYDATA> <DETAILS> <DESCRIPTION>EASE</DESCRIPTION> </DETAILS> <DETAILS> <DESCRIPTION>COMPLEX</DESCRIPTION> </DETAILS> <DETAILS> <DESCRIPTION>SIMPLE</DESCRIPTION> </DETAILS> </MYDATA> I want to display like this using xsl sort it mean custom sort i want to display firts simple second ease and third complex Output :- <MYDATA> <DETAILS> <DESCRIPTION>SIMPLE</DESCRIPTION> </DETAILS> <DETAILS> <DESCRIPTION>EASE</DESCRIPTION> </DETAILS> <DETAILS> <DESCRIPTION>COMPLEX</DESCRIPTION> </DETAILS> </MYDATA>

    Read the article

  • bidirectional bubble sort

    - by davit-datuashvili
    Here is the code for shacker sort or bidirectional bubble sort. Something is wrong. Error is java.lang.ArrayIndexOutOfBoundsException Can anybody help me? public class bidirectional{ public static void main(String[]args){ int x[]=new int[]{12,9,4,99,120,1,3,10}; int j; int n=x.length; int st=-1; while (st<n){ st++; n--; for (j=st;j<n;j++){ if (x[j]>x[j+1]){ int t=x[j]; x[j]=x[j+1]; x[j+1]=t; } } for (j=n;--j>=st;){ if (x[j]>x[j+1]){ int t=x[j]; x[j]=x[j+1]; x[j+1]=t; } } } for (int k=0;k<x.length;k++){ System.out.println(x[k]); } } } thanks i have got result thanks guys i have accepted all answers

    Read the article

  • Sort the $_POST variables

    - by Jerry
    Hello guys Might be an easy for you guys. I am trying to sort the $_POST variables that were sent by a form and update the sorted result in mysql. I am not sure how to do it and appreciate it anyone can help me about it. My main.php //I have a loop here. (omitted) //$k will be increased by 1 every time the loop starts, so I will know the total times of the loops //the form will be submitted to update.php echo "<input type='hidden' name='pickTotal' value='".$k."' />"; echo "<input type='hidden' id='point' name='earnedPoint".$k."' value='".$point."' />"; echo "<input type='hidden' id='users' name='userName".$k."' value='".$userPick['user']."' />"; //loop ends My update.php if(isset($_POST['submit'])){ $pickTotal=$_POST['pickTotal']; //get the total loop for ($p=0;$p<=$pickTotal;$p++){ $userToBeUpdated=$_POST['userName'.$p]; $userPoint=$_POST['earnedPoint'.$p]; //sort the $userPoint here. //I need to find out who got the most points //and list user's place. 1st, 2nd, 3rd...etc. //update my mysql } Thanks for any helps.

    Read the article

  • Sort specific items of an array first

    - by Matt Huggins
    I have a ruby array that looks something like this: my_array = ['mushroom', 'beef', 'fish', 'chicken', 'tofu', 'lamb'] I want to sort the array so that 'chicken' and 'beef' are the first two items, then the remaining items are sorted alphabetically. How would I go about doing this?

    Read the article

  • Hibernate Discriminator sort

    - by mrvreddy
    I am trying to sort the records when queried on discriminator column. I am doing a HQL/ Criteria query for retrieving all the records. Here is my class: abstract class A { ... } @DiscriminatorValue("B") class B extends A { } @DiscriminatorValue("C") class C extends A { } When I return the records, I want it sorted on the discriminator value.

    Read the article

  • how to sort a treemap using bubble sort?

    - by Tsuna Sawada
    27527-683 27525-1179 27525-1571 27525-1813 27525-4911 27526-1303 27526-3641 27525-3989 27525-4083 27525-4670 27526-4102 27526-558 27527-2411 27527-4342 this is the list of key where it is declared as string in a map then i want to sort it in ascending order. how can i use a bubble sorting method inside a map? where the value of the key is a list. in order to get : 27525-1179 27525-1571 27525-1813 27525-3989 27525-4083 27525-4670 27525-4911 27526-558 27526-1303 27526-3641 27526-4102 27527-683 27527-2411 27527-4342

    Read the article

  • passing a class method as opposed to a function in std::sort

    - by memC
    hi, Within a class, I am trying to sort a vector, by passing a method of the same class. But it gives errors at the time of compilation. Can anyone tell what the problem is? Thank you! it gives the following error: argument of type bool (Sorter::)(D&, D&)' does not matchbool (Sorter::*)(D&, D&)' I have also tried using sortBynumber(D const& d1, D const& d2) #include<vector> #include<stdio.h> #include<iostream> #include<algorithm> class D { public: int getNumber(); D(int val); ~D(){}; private: int num; }; D::D(int val){ num = val; }; int D::getNumber(){ return num; }; class Sorter { public: void doSorting(); bool sortByNumber(D& d1, D& d2); std::vector<D> vec_D; Sorter(); ~Sorter(){}; private: int num; }; Sorter::Sorter(){ int i; for ( i = 0; i < 10; i++){ vec_D.push_back(D(i)); } }; bool Sorter::sortByNumber(D& d1, D& d2){ return d1.getNumber() < d2.getNumber(); }; void Sorter::doSorting(){ std::sort(vec_D.begin(), vec_D.end(), this->sortByNumber); }; int main(){ Sorter s; s.doSorting(); std::cout << "\nPress RETURN to continue..."; std::cin.get(); return 0; }

    Read the article

  • Sort a list whit element still in first position

    - by Mercer
    Hello, i have a String list List<String> listString = new ArrayList<String>(); listString.add("faq"); listString.add("general"); listString.add("contact"); I do some processing on the list and i want to sort this list but I want general is still in first position Thx ;)

    Read the article

  • Formula needed: Sort array to array-"snaked"

    - by aw
    After the you guys helped me out so gracefully last time, here is another tricky array sorter for you. I have the following array: a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] I use it for some visual stuff and render it like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Now I want to sort the array to have a "snake" later: // rearrange the array according to this schema 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7 // the original array should look like this a = [1,2,3,4,12,13,14,5,11,16,15,6,10,9,8,7] Now I'm looking for a smart formula / smart loop to do that ticker = 0; rows = 4; // can be n cols = 4; // can be n originalArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; newArray = []; while(ticker < originalArray.length) { //do the magic here ticker++; } Thanks again for the help.

    Read the article

  • sort data in c language

    - by ANIL MANE
    Hello C experts, I need little help on following requirement, as I know very little about C syntaxes. I have data in a file like this 73 54 57 [52] 75 73 65 [23] 65 54 57 [22] 22 59 71 [12] 22 28 54 [2] 65 22 54 73 [12] 65 28 54 73 [52] 22 28 65 73 [42] 65 54 57 73 [22] 22 28 54 73 [4] Where values in bracket denotes the occurrence of that series. I need to sort this data based on the occurrence of the data descending with maximum elements on the top as follows 65 28 54 73 [52] 22 28 65 73 [42] 65 54 57 73 [22] 65 22 54 73 [12] 22 28 54 73 [4] 28 59 71 [122] 73 54 57 [52] 22 28 65 [26] .. . . . and so on... Can someone give me a quick code for this. Thanks in advance.

    Read the article

  • Riddle: Spot the serious bug in this bubble sort implementation

    - by ripper234
    (No, this isn't a homework assignment, I just found the bug and thought it might be useful to share it here) import java.util.List; public class BubbleSorter { public <T extends Comparable<T>> void sort(List<T> list) { while (true) { boolean didWork = false; for (int i = 0; i < list.size() - 1; ++i) { if (list.get(i).compareTo(list.get(i + 1)) > 0) { swap(list, i, i + 1); didWork = true; break; } } if (!didWork) return; } } private static <T> void swap(List<T> list, int i, int j) { T tmp = list.get(i); list.set(i, list.get(j)); list.set(j, tmp); } }

    Read the article

  • PHP Sort a multidimensional array by element containing date

    - by user270797
    I have an array such as: Array ( [0] => Array ( [id] => 2 [type] => comment [text] => hey [datetime] => 2010-05-15 11:29:45 ) [1] => Array ( [id] => 3 [type] => status [text] => oi [datetime] => 2010-05-26 15:59:53 ) [2] => Array ( [id] => 4 [type] => status [text] => yeww [datetime] => 2010-05-26 16:04:24 ) ) Can anyone suggest a way to sort/order this based on the datetime element?

    Read the article

  • Formula needed: Sort Array

    - by aw
    I have the following array: a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] I use it for some visual stuff like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Now I want to sort the array like this: 1 3 6 10 2 5 9 13 4 8 12 15 7 11 14 16 //So the original array should look like this: a = [1,5,2,9,6,3,13,10,7,4,14,11,8,15,12,16] Yeah, now I'm looking for a smart formula to do that ticker = 0; originalArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] newArray = []; while(ticker < originalArray.length) { //do the magic here ticker++; }

    Read the article

  • How can I use STL sort in c++ to sort some values in the class?

    - by Morteza M.
    I have a class named Graph, in this class I have a member named V, it is a vector. I have a struct named Edge, and a list of Edges. like below: struct Edge{ int u; int v; Edge(int u,int v){ this-u=u; this-v=v; } }; class Graph{ vector < Vertex > V; . . . int edgeCmp(Edge* x,Edge* y){ return (V[x-v].dv].d)?1:0; } void someFunction(){ list backEdges; backEdges.sort(&Graph::edgeCmp); } } But it doesn't work!! may someone help me to do such a thing?

    Read the article

  • natural sort of text and numbers, JavaScript

    - by ptrn
    I'm looking for the easiest way to sort an array that consists of numbers and text, and a combination of these. E.g. '123asd' '19asd' '12345asd' 'asd123' 'asd12' turns into '19asd' '123asd' '12345asd' 'asd12' 'asd123' This is going to be used in combination with the solution to another question I've asked here. The sorting function in itself works, what I need is a function that can say that that '19asd' is smaller than '123asd'. I'm writing this in JavaScript. Edit: as adormitu pointed out, what I'm looking for is a function for natural sorting

    Read the article

  • Velocity sort XML file with dynamic-elements

    - by shr_deadman
    Let's say I have a XML file wich looks like this: <root> <dynamic-element name='name' type='text' repeatable='true'> <dynamic-element name='prename' type='text' repeatable='false'> </dynamic element> </dynamic-element> </root> In Liferay the XML file will be filled with input. At the and I will have multiple $name-elements. The question is how I can sort the elements before I print them out with #foreach ($name in $name.getSiblings()) $name.prename.getData() $name.getData() #end thanks, Matthew

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >