Search Results

Search found 9431 results on 378 pages for 'bubble sort'.

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

  • Sort objects and polymorphism

    - by ritmbo
    Suppose I have a class A. And B and C are child of A. Class A has a generic algorithm for sorting arrays of type A, so that I could use it for B and C without writing again the algorithm for each. In the algorithm, sometimes I have to swap. The problem is that I can only see the objects as type A, and if I do: A aux = array[i] array[i] = array[j] array[j] = aux I think I have a problem. Because array[i], maybe its of type B, and aux is of type A, so I think I'm losing information. I'm sure u understand this situation... how can I sort a generic array of objects using a father method algorithm?

    Read the article

  • heap sort function explanation needed

    - by Codeguru
    Hello, Can someone clearly explain me how these functions of heap sort are working?? void heapSort(int numbers[], int array_size) { int i, temp; for (i = (array_size / 2)-1; i >= 0; i--) siftDown(numbers, i, array_size); for (i = array_size-1; i >= 1; i--) { temp = numbers[0]; numbers[0] = numbers[i]; numbers[i] = temp; siftDown(numbers, 0, i-1); } } void siftDown(int numbers[], int root, int bottom) { int done, maxChild, temp; done = 0; while ((root*2 <= bottom) && (!done)) { if (root*2 == bottom) maxChild = root * 2; else if (numbers[root * 2] > numbers[root * 2 + 1]) maxChild = root * 2; else maxChild = root * 2 + 1; if (numbers[root] < numbers[maxChild]) { temp = numbers[root]; numbers[root] = numbers[maxChild]; numbers[maxChild] = temp; root = maxChild; } else done = 1; } }

    Read the article

  • Python: Access dictionary value inside of tuple and sort quickly by dict value

    - by Aquat33nfan
    I know that wasn't clear. Here's what I'm doing specifically. I have my list of dictionaries here: dict = [{int=0, value=A}, {int=1, value=B}, ... n] and I want to take them in combinations, so I used itertools and it gave me a tuple (Well, okay it gave me a memory object that I then used enumerate on so I could loop over it and enumerate gave ma tuple): for (index, tuple) in enumerate(combinations(dict, 2)): and this is where I have my problem. I want to identify which of the two items in the combination has the bigger 'int' value and which has the smaller value and assign them to variables (I'm actually using more than 2 in the combination so I can't just say if tuple[0]['int'] tuple[1]['int'] and do the assignment because I'd have to list this out a bunch of times and that's hard to manage). I was going to assign each 'int' value to a variable, sort it in a list, index the 'int' value in the list by 1, 2, 3, 4, 5 ... etc., then go back and access the dictionary I wanted by the int value and then assign the dictionary to a variable so I knew which was bigger. But I have a big list and lists and variable assignments are resource intensive and this is taking a long time (I had only a little bit of that written and it was taking forever to run). So I was hoping someone knew a fast way to do this. I actually could list out every possible combination of assignmnets using the if/thens but it's just like 5 pages of if/thens and assignments and is hard to read and manage when I want to change it. You've probably gathered this, but I"m new at programming. thx

    Read the article

  • Ubuntu App Submission won't allow the "free" bubble to be checked

    - by Compt
    I am at the final stages of the Ubuntu App Developer Showdown, and I'm right at the point where I am submitting my app. The problem I run in to however, is that even though buy is at $0.00, it will not allow me to click on the "free" button, and keep that configuration saved. So when I go to "preview your app", it shows it saying "USD $0.00 ---- Buy" instead of saying "Free ---- Install". So I was wondering if it makes any difference or not.

    Read the article

  • The IT Security Bubble Has Popped

    The blank check IT security enjoyed has been pulled off the table as businesses reassess how much they spend to stay safe. Need some data on the mood? McAfee reports nearly three-quarters of SMBs have cut security spending, even though 71 percent believe a serious attack would put them out of business.

    Read the article

  • The IT Security Bubble Has Popped

    The blank check IT security enjoyed has been pulled off the table as businesses reassess how much they spend to stay safe. Need some data on the mood? McAfee reports nearly three-quarters of SMBs have cut security spending, even though 71 percent believe a serious attack would put them out of business.

    Read the article

  • Search algorithm (with a sort algorithm already implemented)

    - by msr
    Hello, Im doing a Java application and Im facing some doubts in which concerns performance. I have a PriorityQueue which guarantees me the element removed is the one with greater priority. That PriorityQueue has instances of class Event (which implements Comparable interface). Each Event is associated with a Entity. The size of that priorityqueue could be huge and very frequently I will have to remove events associated to an entity. Right now Im using an iterator to run all the priorityqueue. However Im finding it heavy and I wonder if there are better alternatives to search and remove events associated with an entity "xpto". Any suggestions? Thanks!

    Read the article

  • Wordpress: sort into sub-pages, then sort by tag

    - by redconservatory
    I have a wordpress page with two or three sub-pages ("TV", "WEB", "WATCH") and I would like to have the sub-page links on the page itself. So, far, I can pull the sub-pages the following way: <?php $children = wp_list_pages('title_li&child_of='.$post->ID.'depth=1&echo=0'); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?> However, is there a way to loop through $children so I can pull each link by it's tag? i.e. using has_tag('tv'), has_tag('web') Between the wordpress conditional tags and php, I am not sure how to write this.

    Read the article

  • fast algorithm to sort very small set

    - by aaa
    hello. This is the problem I ran into long time ago. I thought I may ask your for your ideas. assume I have very small set of numbers (integers), 4 or 8 elements, that need to be sorted, fast. what would be the best approach/algorithm? my approach was to use the max/min functions only. At this point it becomes somewhat hardware dependent , so let us assume Intel 64-bit processor with SSE3 . Thanks

    Read the article

  • Are there any worse sorting algorithms than Bogosort (a.k.a Monkey Sort)?

    - by womp
    My co-workers took me back in time to my University days with a discussion of sorting algorithms this morning. We reminisced about our favorites like StupidSort, and one of us was sure we had seen a sort algorithm that was O(n!). That got me started looking around for the "worst" sorting algorithms I could find. We postulated that a completely random sort would be pretty bad (i.e. randomize the elements - is it in order? no? randomize again), and I looked around and found out that it's apparently called BogoSort, or Monkey Sort, or sometimes just Random Sort. Monkey Sort appears to have a worst case performance of O(∞), a best case performance of O(n), and an average performance of O(n * n!). Are there any named algorithms that have worse average performance than O(n * n!)? Or are just sillier than Monkey Sort in general?

    Read the article

  • How to sort output of "s3cmd ls"

    - by dba.in.ua
    Amazon "s3cmd ls" takes like this output: 2010-02-20 21:01 1458414588 s3://file.tgz.00 2010-02-20 21:10 1458414527 s3://file.tgz.01 2010-02-20 22:01 1458414588 s3://file.tgz.00 2010-02-20 23:10 1458414527 s3://file.tgz.01 2010-02-20 23:20 1458414588 s3://file.tgz.02 How to select all files of archive, ending at 0 ... X, with the latest date of fileset ? Bash, regexp ? Thanx!

    Read the article

  • fast algorithm implementation to sort very small set

    - by aaa
    hello. This is the problem I ran into long time ago. I thought I may ask your for your ideas. assume I have very small set of numbers (integers), 4 or 8 elements, that need to be sorted, fast. what would be the best approach/algorithm? my approach was to use the max/min functions. I guess my question pertains more to implementation, rather than type of algorithm. At this point it becomes somewhat hardware dependent , so let us assume Intel 64-bit processor with SSE3 . Thanks

    Read the article

  • PHP Associative array sort

    - by Mithun
    I have an array like one below. Currently it is sorted alphabetically by the OwnerNickName field. Now i want to brig the array entry with OwnerNickName 'My House' as the first entry of the array and rest sorted alphabetically by OwnerNickName. Any idea? Array ( [0318B69D-5DEB-11DF-9D7E-0026B9481364] => Array ( [OwnerNickName] => andy [Rooms] => Array ( [0] => Array ( [Label] => Living Room [RoomKey] => FC795A73-695E-11DF-9D7E-0026B9481364 ) ) ) [286C29DE-A9BE-102D-9C16-00163EEDFCFC] => Array ( [OwnerNickName] => anton [Rooms] => Array ( [0] => Array ( [Label] => KidsRoom [RoomKey] => E79D7991-64DC-11DF-9D7E-0026B9481364 ) [1] => Array ( [Label] => Basement [RoomKey] => CC12C0C4-68AA-11DF-9D7E-0026B9481364 ) [2] => Array ( [Label] => Family Room [RoomKey] => 67A280D4-64D9-11DF-9D7E-0026B9481364 ) ) ) [8BE18F84-AC22-102D-9C16-00163EEDFCFC] => Array ( [OwnerNickName] => mike [Rooms] => Array ( [0] => Array ( [Label] => Family Room [RoomKey] => 1C6AFB39-6835-11DF-9D7E-0026B9481364 ) ) ) [29B455DE-A9BC-102D-9C16-00163EEDFCFC] => Array ( [OwnerNickName] => My House [Rooms] => Array ( [0] => Array ( [Label] => Basement [RoomKey] => 61ECFAB2-6376-11DF-9D7E-0026B9481364 ) [1] => Array ( [Label] => Rec Room [RoomKey] => 52B8B781-6376-11DF-9D7E-0026B9481364 ) [2] => Array ( [Label] => Deck [RoomKey] => FFEB4102-64DE-11DF-9D7E-0026B9481364 ) [3] => Array ( [Label] => My Room2 [RoomKey] => 112473E4-64DF-11DF-9D7E-0026B9481364 ) [4] => Array ( [Label] => Bar Room [RoomKey] => F82C47A8-64DE-11DF-9D7E-0026B9481364 ) ) ) )

    Read the article

  • Help with a sort method

    - by Capsud
    Hi there, If i have an array of strings for example Static final String[] TEST = new String[] { "g","a","b","t","e" }; How would i go about sorting this in alphabetical order please?

    Read the article

  • How to sort multiple arrays in PHP

    - by Phil Jackson
    hi, i have wrote a script to produce an array of data but now want to display in order of score. The array outputs as follows; [display_name] => Array ( [0] => ACT_Web_Designs [1] => user1_design [2] => user2_design ) [proffesion] => Array ( [0] => Web Developer [1] => web developer [2] => Web Developer ) [score] => Array ( [0] => 15 [1] => 6 [2] => 15 ) [img] => Array ( [0] => ./?0000=gif&0001=3fadb8c362ff39f3322909899ff14760&0002=prof_pic [1] => [2] => ) so in a nutshell I am wanting it to be converted as follows; [display_name] => Array ( [0] => ACT_Web_Designs [1] => user2_design [2] => user1_design ) [proffesion] => Array ( [0] => Web Developer [1] => web developer [2] => Web Developer ) [score] => Array ( [0] => 15 [1] => 15 [2] => 6 ) [img] => Array ( [0] => ./?0000=gif&0001=3fadb8c362ff39f3322909899ff14760&0002=prof_pic [1] => [2] => ) I have been looking at asort() but cant get anything to work. any help would be much appreciated.

    Read the article

  • Sort array by keys of another array.

    - by marbrun
    Hello There are 2 arrays, both with the same length and with the same keys: $a1 = [1=>2000,65=>1354,103=>1787]; $a2 = [1=>'hello',65=>'hi',103=>'goodevening']; asort($a1); The keys of a1 and a2 are id's from a database. a1 gets sorted by value. Once sorted, how can we use the same sorting order in a2? Thanks!

    Read the article

  • PHP Sort Array By SubArray Value

    - by Sjwdavies
    I've got the following structue of array: Array ( [0] => Array ( [configuration_id] => 10 [id] => 1 [optionNumber] => 3 [optionActive] => 1 [lastUpdated] => 2010-03-17 15:44:12 ) [1] => Array ( [configuration_id] => 9 [id] => 1 [optionNumber] => 2 [optionActive] => 1 [lastUpdated] => 2010-03-17 15:44:12 ) [2] => Array ( [configuration_id] => 8 [id] => 1 [optionNumber] => 1 [optionActive] => 1 [lastUpdated] => 2010-03-17 15:44:12 ) ) What's the best way for order the array, in an incremental way based on the optionNumber? So the results look like: Array ( [0] => Array ( [configuration_id] => 8 [id] => 1 [optionNumber] => 1 [optionActive] => 1 [lastUpdated] => 2010-03-17 15:44:12 ) [1] => Array ( [configuration_id] => 9 [id] => 1 [optionNumber] => 2 [optionActive] => 1 [lastUpdated] => 2010-03-17 15:44:12 ) [2] => Array ( [configuration_id] => 10 [id] => 1 [optionNumber] => 3 [optionActive] => 1 [lastUpdated] => 2010-03-17 15:44:12 ) )

    Read the article

  • Distribute Sort Sample Service

    - by kaleidoscope
    How it works? Using the front-end of the service, a user can specify a size in MB for the input data set to sort. Algorithm CreateAndSplit The CreateAndSplit task generates the input data and stores them as 10 blobs in the utility storage. The URLs to these blobs are packaged as Separate work items and written to the queue. · Separate The Separate task reads the blobs with the random numbers created in the CreateAndSplit task and places the random numbers into buckets. The interval of the numbers that go into one bucket is chosen so that the expected amount of numbers (assuming a uniform distribution of the numbers in the original data set) is around 100 kB. Each bucket is represented as a blob container in utility storage. Whenever there are 10 blobs in one bucket (i.e., the placement in this bucket is complete because we had 10 original splits), the separate task will generate a new Sort task and write the task into the queue. · Sort The Sort task merges all blobs in a single bucket and sorts them using a standard sort algorithm. The result is stored as a blob in utility storage. · Concat The concat task merges the results of all Sort tasks into a single blob. This blob can be downloaded as a text file using this Web page. As the resulting file is presented in text format, the size of the file is likely to be larger than the specified input file. Anish

    Read the article

  • C# Multiple Property Sort

    - by Ben Griswold
    As you can see in the snippet below, sorting is easy with Linq.  Simply provide your OrderBy criteria and you’re done.  If you want a secondary sort field, add a ThenBy expression to the chain.  Want a third level sort?  Just add ThenBy along with another sort expression. var projects = new List<Project>     {         new Project {Description = "A", ProjectStatusTypeId = 1},         new Project {Description = "B", ProjectStatusTypeId = 3},         new Project {Description = "C", ProjectStatusTypeId = 3},         new Project {Description = "C", ProjectStatusTypeId = 2},         new Project {Description = "E", ProjectStatusTypeId = 1},         new Project {Description = "A", ProjectStatusTypeId = 2},         new Project {Description = "C", ProjectStatusTypeId = 4},         new Project {Description = "A", ProjectStatusTypeId = 3}     };   projects = projects     .OrderBy(x => x.Description)     .ThenBy(x => x.ProjectStatusTypeId)     .ToList();   foreach (var project in projects) {     Console.Out.WriteLine("{0} {1}", project.Description,         project.ProjectStatusTypeId); } Linq offers a great sort solution most of the time, but what if you want or need to do it the old fashioned way? projects.Sort ((x, y) =>         Comparer<String>.Default             .Compare(x.Description, y.Description) != 0 ?         Comparer<String>.Default             .Compare(x.Description, y.Description) :         Comparer<Int32>.Default             .Compare(x.ProjectStatusTypeId, y.ProjectStatusTypeId));   foreach (var project in projects) {     Console.Out.WriteLine("{0} {1}", project.Description,         project.ProjectStatusTypeId); } It’s not that bad, right? Just for fun, let add some additional logic to our sort.  Let’s say we wanted our secondary sort to be based on the name associated with the ProjectStatusTypeId.  projects.Sort((x, y) =>        Comparer<String>.Default             .Compare(x.Description, y.Description) != 0 ?        Comparer<String>.Default             .Compare(x.Description, y.Description) :        Comparer<String>.Default             .Compare(GetProjectStatusTypeName(x.ProjectStatusTypeId),                 GetProjectStatusTypeName(y.ProjectStatusTypeId)));   foreach (var project in projects) {     Console.Out.WriteLine("{0} {1}", project.Description,         GetProjectStatusTypeName(project.ProjectStatusTypeId)); } The comparer will now consider the result of the GetProjectStatusTypeName and order the list accordingly.  Of course, you can take this same approach with Linq as well.

    Read the article

  • What's the best way to store sort order in SQL?

    - by Duracell
    The guys at the top want sort order to be customizable in our app. So I have a table that effectively defines the data type. What is the best way to store our sort order. If I just created a new column called 'Order' or something, every time I updated the order of one row I imagine I would have to update the order of every row to ensure posterity. Is there a better way to do it?

    Read the article

  • Why does C qicksort function implementation works much slower (tape comparations, tape swapping) than bobble sort function?

    - by Artur Mustafin
    I'm going to implement a toy tape "mainframe" for a students, showing the quickness of "quicksort" class functions (recursive or not, does not really matters, due to the slow hardware, and well known stack reversal techniques) comparatively to the "bubblesort" function class, so, while I'm clear about the hardware implementation ans controllers, i guessed that quicksort function is much faster that other ones in terms of sequence, order and comparation distance (it is much faster to rewind the tape from the middle than from the very end, because of different speed of rewind). Unfortunately, this is not the true, this simple "bubble" code shows great improvements comparatively to the "quicksort" functions in terms of comparison distances, direction and number of comparisons and writes. So I have 3 questions: Does I have mistaken in my implememtation of quicksort function? Does I have mistaken in my implememtation of bubblesoft function? If not, why the "bubblesort" function is works much faster in (comparison and write operations) than "quicksort" function? I already have a "quicksort" function: void quicksort(float *a, long l, long r, const compare_function& compare) { long i=l, j=r, temp, m=(l+r)/2; if (l == r) return; if (l == r-1) { if (compare(a, l, r)) { swap(a, l, r); } return; } if (l < r-1) { while (1) { i = l; j = r; while (i < m && !compare(a, i, m)) i++; while (m < j && !compare(a, m, j)) j--; if (i >= j) { break; } swap(a, i, j); } if (l < m) quicksort(a, l, m, compare); if (m < r) quicksort(a, m, r, compare); return; } } and the kind of my own implememtation of the "bubblesort" function: void bubblesort(float *a, long l, long r, const compare_function& compare) { long i, j, k; if (l == r) { return; } if (l == r-1) { if (compare(a, l, r)) { swap(a, l, r); } return; } if (l < r-1) { while(l < r) { i = l; j = l; while (i < r) { i++; if (!compare(a, j, i)) { continue; } j = i; } if (l < j) { swap(a, l, j); } l++; i = r; k = r; while(l < i) { i--; if (!compare(a, i, k)) { continue; } k = i; } if (k < r) { swap(a, k, r); } r--; } return; } } I have used this sort functions in a test sample code, like this: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <conio.h> long swap_count; long compare_count; typedef long (*compare_function)(float *, long, long ); typedef void (*sort_function)(float *, long , long , const compare_function& ); void init(float *, long ); void print(float *, long ); void sort(float *, long, const sort_function& ); void swap(float *a, long l, long r); long less(float *a, long l, long r); long greater(float *a, long l, long r); void bubblesort(float *, long , long , const compare_function& ); void quicksort(float *, long , long , const compare_function& ); void main() { int n; printf("n="); scanf("%d",&n); printf("\r\n"); long i; float *a = (float *)malloc(n*n*sizeof(float)); sort(a, n, &bubblesort); print(a, n); sort(a, n, &quicksort); print(a, n); free(a); } long less(float *a, long l, long r) { compare_count++; return *(a+l) < *(a+r) ? 1 : 0; } long greater(float *a, long l, long r) { compare_count++; return *(a+l) > *(a+r) ? 1 : 0; } void swap(float *a, long l, long r) { swap_count++; float temp; temp = *(a+l); *(a+l) = *(a+r); *(a+r) = temp; } float tg(float x) { return tan(x); } float ctg(float x) { return 1.0/tan(x); } void init(float *m,long n) { long i,j; for (i = 0; i < n; i++) { for (j=0; j< n; j++) { m[i + j*n] = tg(0.2*(i+1)) + ctg(0.3*(j+1)); } } } void print(float *m, long n) { long i, j; for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { printf(" %5.1f", m[i + j*n]); } printf("\r\n"); } printf("\r\n"); } void sort(float *a, long n, const sort_function& sort) { long i, sort_compare = 0, sort_swap = 0; init(a,n); for(i = 0; i < n*n; i+=n) { if (fmod (i / n, 2) == 0) { compare_count = 0; swap_count = 0; sort(a, i, i+n-1, &less); if (swap_count == 0) { compare_count = 0; sort(a, i, i+n-1, &greater); } sort_compare += compare_count; sort_swap += swap_count; } } printf("compare=%ld\r\n", sort_compare); printf("swap=%ld\r\n", sort_swap); printf("\r\n"); }

    Read the article

  • lambda vs. operator.attrGetter('xxx') as sort key in Python

    - by Paul McGuire
    I am looking at some code that has a lot of sort calls using comparison functions, and it seems like it should be using key functions. If you were to change seq.sort(lambda x,y: cmp(x.xxx, y.xxx)), which is preferable: seq.sort(key=operator.attrgetter('xxx')) or: seq.sort(key=lambda a:a.xxx) I would also be interested in comments on the merits of making changes to existing code that works.

    Read the article

  • speech bubbles like in comics for iphone

    - by plspl
    I am new to iphone application development. I am building an iphone app where the user needs to be able to add speech bubbles (think comics) over existing images. I have some questions on how to implement this, Have an empty speech bubble image and overlay it over existing image - Do I use a separate UIImage for the speech bubble? Or should I draw the speech bubble myself? Allow the user to move the speech bubble using touch- Any pointers or examples would be great! Also let him resize the speech depending on the amount of text - Any pointers or examples would be great! Finally he should be able to add text to speech bubble - Is there a way to add textbox over an existing image? Thanks,

    Read the article

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