Search Results

Search found 10131 results on 406 pages for 'natural sort'.

Page 32/406 | < Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >

  • Unreasonable errors in merge sort

    - by Alexxx
    i have the following errors - please help me to find the error: 9 IntelliSense: expected a '}' 70 4 it points on the end of the code - but there are no open { anywhere!! so why?? 8 IntelliSense: expected a ';' 57 1 it points on the { after the void main but why to put ; after the { of the void main?? Error 7 error C1075: end of file found before the left brace '{' at 70 1 points to the beginig of the code - why??? #include <stdio.h> #include <stdlib.h> void merge(int *a,int p,int q,int r) { int i=p,j=q+1,k=0; int* temp=(int*)calloc(r-p+1, sizeof(int)); while ((i<=q)&& (j<=r)) if(a[i]<a[j]) temp[k++]=a[i++]; else temp[k++]=a[j++]; while(j<=r) // if( i>q ) temp[k++]=a[j++]; while(i<=q) // j>r temp[k++]=a[i++]; for(i=p,k=0;i<=r;i++,k++) // copy temp[] to a[] a[i]=temp[k]; free(temp); } void merge_sort(int *a,int first, int last) { int middle; if(first < last) { middle=(first+last)/2; merge_sort(a,first,middle); merge_sort(a,middle+1,last); merge(a,first,middle,last); { } void main() { int a[] = {9, 7, 2, 3, 5, 4, 1, 8, 6, 10}; int i; merge_sort(a, 0, 9); for (i = 0; i < 10; i++) printf ("%d ", a[i]);

    Read the article

  • C# some sort of plugin system

    - by nLL
    Hi, I am a mobile web developer and trying to monetize my traffic with mobile ad services and i have a problem. First of all to get most of out of your ads you usually need to do server side request to advert company's servers and there are quite few ad services. Problem starts when you want to use them in one site. All have different approaches to server side calls and trying to maintain and implement those ad codes becomes pain after a while. So I decided to write a class system where i can simply create methods for every company and upload it to my site. So far i have public Advert class public AdPublisher class with GetAd method that returns an Advert public Adservice class that has Service names as enum I also have converted server request codes of all ad services i use to classes. It works ok but I want to be able to create an ad service class upload it so that asp.net app can import/recognize it automatically like a plugin system. As I am new to .net I have no idea where to start or how to do it. To make thing clear here are my classes namespace Mobile.Publisher { public class AdPublisher { public AdPublisher() { IsTest = false; } public bool IsTest { get; set; } public HttpRequest CurrentVisitorRequestInfo { get; set; } public Advert GetAd(AdService service) { Advert returnAd = new Advert(); returnAd.Success = true; if (this.CurrentVisitorRequestInfo == null) { throw new Exception("CurrentVisitorRequestInfo for AdPublisher not set!"); } if (service == null) { throw new Exception("AdService not set!"); } if (service.ServiceName == AdServices.Admob) { returnAd.ReturnedAd = AdmobAds("000000"); } return returnAd; } } public enum AdServices { Admob, ServiceB, ServiceC } public class Advert { public bool Success { get; set; } public string ReturnedAd { get; set; } } public partial class AdService { public AdServices ServiceName { get; set; } public string PublisherOrSiteId { get; set; } public string ZoneOrChannelId { get; set; } } private string AdmobAds(string publisherid) { //snip return "test" } } Basically i want to be able to add another ad service and code like private string AdmobAds(string publisherid){ } So that it can be imported and recognised as ad service. I hope i was clear enough

    Read the article

  • I need to sort the facets that come back from SOLR by relevancy

    - by Pinguthepenguin
    I have within my SOLR index song objects which belong to a higher level album object. An example is shown below: <song> <album title>Blood Sugar Sex Magic</album title> <song title>Under the Bridge</song title> <description>A sad song about junkies</description> </song> What I can do at the moment is create a facet on the album title so that a search on songs will also show me what albums contain hits for that keyword. The default behaviour for SOLR is that the facets are shown in the order of most hits to least. However what I want to achieve is the facet list to be sorted according to the relevancy of the top hit for that album. For example a search on the word "sad" may show a facet with one hit for "Blood Sugar Sex Magic" and there may also be an album called "Sad Clown songs" where there are 10 hits. "Sad clown songs" will show as the first facet even though it may be that "Under the bridge" comes up as the most relevant song. My question is how can I get all the facets back but then have them ordered by the relevancy of the songs within them? If I would need to change or extend some underlying SOLR code what would that be? Thanks in advance.

    Read the article

  • t-sql help with recursive sort of query

    - by stackoverflowuser
    Hi Based on the following table ID Path --------------------------------------- 1 \\Root 2 \\Root\Node0 3 \\Root\Node0\Node1 4 \\Root\Node0\Node2 5 \\Root\Node3 6 \\Root\Node3\Node4 7 \\Root\Node5 ... N \\Root\Node5\Node6\Node7\Node8\Node9\Node10 so on... There are around 1000 rows in this table. I want to display individual node in seperate columns. Maximum columns to be displayed 5 (i.e. node till 5 level deep). So the output will look as below ID Path Level 0 Level 1 Level 2 Level 3 Level 4 Level 5 ---------------------------------------------------------------------------------------- 1 \\Root Root Null Null Null Null Null 2 \\Root\Node0 Root Node 0 Null Null Null Null 3 \\Root\Node0\Node1 Root Node 0 Node 1 Null Null Null 4 \\Root\Node0\Node2 Root Node 0 Node 2 Null Null Null 5 \\Root\Node3 Root Node 3 Null Null Null Null 6 \\Root\Node3\Node4 Root Node 3 Node 4 Null Null Null 7 \\Root\Node5 Root Node 5 Null Null Null Null ... N (see in above table) Root Node 5 Node 6 Node 7 Node 8 Node 9 The only way i can think of is to open a cursor, loop through each row and perform string split, just fetch the first 5 nodes and then insert into a temp table. Pls. suggest. Thanks

    Read the article

  • Generate all permutations with sort constraint

    - by Moos Hueting
    Hi! I have a list consisting of other lists and some zeroes, for example: x = [[1, 1, 2], [1, 1, 1, 2], [1, 1, 2], 0, 0, 0] I would like to generate all the combinations of this list while keeping the order of the inner lists unchanged, so [[1, 1, 2], 0, 0, [1, 1, 1, 2], [1, 1, 2], 0] is fine, but [[1, 1, 1, 2], [1, 1, 2], 0, 0, [1, 1, 2], 0] isn't. I've got the feeling that this should be fairly easy in Python, but I just don't see it. Could somebody help me out?

    Read the article

  • PHP> Sort query results by name while letting each letter be on the top sometimes

    - by Don
    Hi, I'm currently working on a site that will display a list of online shops, Each shop will be stored on my database and I'll be using PHP to select and display them. But since those shops will pay me, I want to let each shop to be on the top of the list sometimes, (for example if the shop name starts with a "Z", they will probably complain for being on the bottom of the list all the time, so I want to keep it fair). So I thought about letting each letter be on the top of the list for an hour, but i have no idea how to do that.. Is that even possible? Thanks in advance!

    Read the article

  • quick sort problem

    - by farka
    I use qsort from C libary and I have datatype Element_type **pElement and Element_type is struct typedef element_type {int ,char ....} example, and i call quicksor function with qsort(*pElement,iCountElement,(size_t)sizeof(Element_type),compare); and callback function static int compare(const void *p1, const void *p2) { Element_type *a1 = (Element_type *)p1; Element_type *a2 = (Element_type *)p2; return ( (a2)->iServiceId < (a1)->iServiceId ); } but I always get segmentation fault. Why?

    Read the article

  • NSFetchedResultsController sort different sections differently (ascending/descending)?

    - by PartiallyFinite
    In my app, I have a task list (no, it's not just another todo app), and I display the tasks in a UITableView using an NSFetchedResultsController. Here is the relevant initialisation code: NSSortDescriptor *dueDateSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"due" YES]; NSSortDescriptor *completionSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"completed" ascending:YES]; [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:completionSortDescriptor, dueDateSortDescriptor, nil]]; _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:@"completed" cacheName:nil]; What this does is sorts the tasks such that I have an incomplete tasks section at the top, sorting with the tasks due first on top, and tasks due later further down. This all works. However, this means that the second section, the one with the completed tasks, also sorts this way, so the earliest due tasks are on top. What I want to do is change it so the second section sorts the other way around (in descending order), but the first section stays sorted in ascending order. Is this even possible? How would I go about this? Why I want to do this: The way it currently works, the tasks at the top of the second section (and therefore the most visible) are the ones that were completed ages ago. It is more likely that the user would want to see the tasks that are more recently completed (and uncheck one if it was accidentally checked), and presumably the tasks with a more recent due date were more recently completed. I am happy to add a separate completion date field to the Core Data task object if necessary (This isn't a shipping application yet, so I can change the data format however I like).

    Read the article

  • Sort Strings by first letter [C]

    - by Blackbinary
    I have a program which places structures in a linked list based on the 'name' they have stored in them. To find their place in the list, i need to figure out if the name im inserting is earlier or later in the alphabet then those in the structures beside it. The names are inside the structures, which i have access to. I don't need a full comaparison if that is more work, even just the first letter is fine. Thanks for the help!

    Read the article

  • How can you Merge sort a .Net framework LinkedList (of T)

    - by Andronicus
    There's a few questions discussing Merge sorting a LinkedList, but how can I do it with the C# LinkedList? Since the LinkedListNode Next and Previous properties are read-only most of the in-place algorithms I've come across are not possible. I've resorted to removing all the nodes, sorting them with a .OrderBy(node = node.Value) and then re-inserting them into the Linked list, but it's fairly crude.

    Read the article

  • effective functonal sort

    - by sreservoir
    I'm programming a function for a ti-nspire, so I can't use the builtins from inside a function. what is the most generally efficient algorithm for sorting a list of numbers without modifying the list itself? (recursion and list-splitting are fair game, as is general use of math.)

    Read the article

  • Creating a sort function for a generic list

    - by Andrey
    I have a method for sorting generic lists by the object fields: public static IQueryable<T> SortTable<T>(IQueryable<T> q, string sortfield, bool ascending) { var p = Expression.Parameter(typeof(T), "p"); if (typeof(T).GetProperty(sortfield).PropertyType == typeof(int?)) { var x = Expression.Lambda<Func<T, int?>>(Expression.Property(p, sortfield), p); if (ascending) q = q.OrderBy(x); else q = q.OrderByDescending(x); } else if (typeof(T).GetProperty(sortfield).PropertyType == typeof(int)) { var x = Expression.Lambda<Func<T, int>>(Expression.Property(p, sortfield), p); if (ascending) q = q.OrderBy(x); else q = q.OrderByDescending(x); } else if (typeof(T).GetProperty(sortfield).PropertyType == typeof(DateTime)) { var x = Expression.Lambda<Func<T, DateTime>>(Expression.Property(p, sortfield), p); if (ascending) q = q.OrderBy(x); else q = q.OrderByDescending(x); } // many more for every type return q; } Is there any way I can collapse those ifs to a single generic statement? The main problem is that for the part Expression.Lambda<Func<T, int>> I am not sure how to write it generically.

    Read the article

  • How to sort it!?

    - by user334269
    The following is my DB data, how can I sorting it by sid and prev_sid with php/mysql!? sid prev_sid type 000 197 app_home 197 198 page_teach 198 218 page_teach 199 211 page_step 211 207 link 218 559 page_step 559 199 page_step Result: sid prev_sid type 000 197 app_home 197 198 page_teach 198 218 page_teach 218 559 page_step 559 199 page_step 199 211 page_step 211 207 link 000 197 198 218 559 199 199 211 207

    Read the article

  • Sort a list numerically in Python

    - by Matthew
    So I have this list, we'll call it listA. I'm trying to get the [3] item in each list e.g. ['5.01','5.88','2.10','9.45','17.58','2.76'] in sorted order. So the end result would start the entire list over again with Santa at the top. Does that make any sense? [['John Doe', u'25.78', u'20.77', '5.01'], ['Jane Doe', u'21.08', u'15.20', '5.88'], ['James Bond', u'20.57', u'18.47', '2.10'], ['Michael Jordan', u'28.50', u'19.05', '9.45'], ['Santa', u'31.13', u'13.55', '17.58'], ['Easter Bunny', u'17.20', u'14.44', '2.76']]

    Read the article

  • question about in -place sort

    - by davit-datuashvili
    for example we have following array char data[]=new char[]{'A','S','O','R','T','I','N','G','E','X','A','M','P','L','E'}; and index array int a[]=new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}: void insitu(char data[],int a[],N){ for (int i=0;i<N;i++) { char v=data[i]; int j,int k; for (k=i;a[k]!=i;k=a[j];a[j]=j) { j=k;data[k]=data[a[k]; } data[k]=v; a[k]=k; } i have question what is initialize value of j? when i run this code it asks me to initialize j and what should do? }

    Read the article

  • Interview question: C program to sort a binary array in O(n)

    - by Zacky112
    I've comeup with the following program to do it, but it does not seem to work and goes into infinite loop. Its working is similar to quicksort. int main() { int arr[] = {1,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1}; int N = 18; int *front, *last; front = arr; last = arr + N; while(front <= last) { while( (front < last) && (*front == 0) ) front++; while( (front < last) && (*last == 1) ) last--; if( front < last) { int temp = *front; *front = *last; *last = temp; front ++; last--; } } for(int i=0;i<N;i++) printf("%d ",arr[i]); return 0; }

    Read the article

  • C++ Bubble Sorting for Singly Linked List [closed]

    - by user1119900
    I have implemented a simple word frequency program in C++. Everything but the sorting is OK, but the sorting in the following script does not work. Any emergent help will be great.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <iostream> #include <fstream> #include <cstdio> using namespace std; #include "ProcessLines.h" struct WordCounter { char *word; int word_count; struct WordCounter *pNext; // pointer to the next word counter in the list }; /* pointer to first word counter in the list */ struct WordCounter *pStart = NULL; /* pointer to a word counter */ struct WordCounter *pCounter = NULL; /* Print statistics and words */ void PrintWords() { ... pCounter = pStart; bubbleSort(pCounter); ... } //end-PrintWords void bubbleSort(struct WordCounter *ptr) { WordCounter *temp = ptr; WordCounter *curr; for (bool didSwap = true; didSwap;) { didSwap = false; for (curr = ptr; curr->pNext != NULL; curr = curr->pNext) { if (curr->word > curr->pNext->word) { temp->word = curr->word; curr->word = curr->pNext->word; curr->pNext->word = temp->word; didSwap = true; } } } }

    Read the article

  • How to sort MySQL query by two columns

    - by user334269
    The following is my DB data, how can I sorting it by sid and prev_sid with php/mysql!? sid prev_sid type 000 197 app_home 197 198 page_teach 198 218 page_teach 199 211 page_step 211 207 link 218 559 page_step 559 199 page_step Result: sid prev_sid type 000 197 app_home 197 198 page_teach 198 218 page_teach 218 559 page_step 559 199 page_step 199 211 page_step 211 207 link 000 197 198 218 559 199 199 211 207

    Read the article

  • Sort MySQL result set using comparison between 2 columns of same value type

    - by Kyobul
    Hello, I have a table containing last_updated_1 and last_updated_2 columns, used respectively for text and images update time on a post. I wish I could get a result set of 10 rows based on all time last updated records contained in the 2 columns, ex. row 1 = last_updated_1 record, row 2 = last_updated_2 record, row 3 = last_updated_1 record, etc. How could I compare inside a MySQL query the both columns values, to get unique & mixed result set ? Thank you in advance for your help

    Read the article

  • Help doing a dynamic sort?

    - by Kevin
    I have a notifications table which contains different types of notifications for different events. Inside the table is a notifications_type:string column that contains the type of notification, i.e. "foo" or "bar" or "oof" I want the user to be able to select what notifications they want to display, so there are checkboxes below the result that correspond to prefs_display_foo:boolean, prefs_display_bar:boolean in the User model. What is an elegant way for me to set the :conditions in the find to properly display the sorted results? Also, currently I have it as a method in the user, but how would I do it as a has_many :notifications, :conditions = .....

    Read the article

< Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >