Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8429913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:28:01+00:00 2026-06-10T05:28:01+00:00

I have created two functions that sorts a list using bubble sort, but I

  • 0

I have created two functions that sorts a list using bubble sort, but I would like to change the sort style to quick sort.

I found this quick sort algorithm

http://snipd.net/quicksort-in-c

These are my two functions:

    protected void sort_by_section_name()
    {
        int num1, num2;
        for (var i = section_names.Count - 1; i > 0; i -= 1)
        {
            for (var j = 0; j < i; j += 1)
            {
                num1 = get_number_from_section(section_names[j]);
                num2 = get_number_from_section(section_names[j + 1]);
                if (num1 > num2)
                {
                    swap_list_strings(section_names, j, j + 1);
                    swap_object_items(item_group_list, j, j + 1);
                }
            }
        }
    }

    protected void sort_items()
    {
        int num1, num2;
        List<SPListItem> temp;
        for (var k = 0; k < item_group_list.Count; k += 1)
        {
            temp = (List<SPListItem>)item_group_list[k];
            for (var i = temp.Count - 1; i > 0; i -= 1)
            {
                for (var j = 0; j < i; j += 1)
                {
                    num1 = Convert.ToInt32((temp[j])[ORDER_BY_COLUMN]);
                    num2 = Convert.ToInt32((temp[j + 1])[ORDER_BY_COLUMN]);
                    if (num1 > num2)
                    {
                        swap_list_items(temp, j, j + 1);
                    }
                }
            }
        }
    }

For sort_items, its an array of arrays, so the bubble sort stuff is in a for loop.

I don’t understand how to change these two functions into using the quicksort.

Can someone please help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:28:03+00:00Added an answer on June 10, 2026 at 5:28 am

    So you have a List<SPListItem> and you want them sorted, using an efficient sorting algorithm (aka not bubblesort) based on the numeric value of some field. This is easy, and doesn’t involve you re-implementing quicksort.

    List<SPListItem> list = ...;
    
    var sortedData = list.OrderBy(item => Convert.ToInt32(item["fieldName"]));
    

    It’s also worth noting that when possible it’s usually better to sort your data on the database, rather than on the webserver. You should be able to add an Order By clause to the CAML query generating those SPListItems and let it do the sort.

    It appears that you’re sorting two different data structures that are “parallel” (the item at the same index of both structures “belong” together). This is generally undesirable. While there are ways to perform a sort on both structures, what you really should be doing is making a single structure such that each item holds onto everything that logically represents that one item. In many cases this means creating a new class that has properties for each piece of data. You can then populate a collection of this new composite class and sort that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two functions that sum and subtract the numeric values of two
Possible Duplicate: jQuery delay between animations I have created two functions: One that animates
I have two functions that together build a treeview list on my website. It's
I have a function that creates time intervals between two time marks. The function
I have a problem to create a preprocessor macro function, that concatenates two Strings
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
I have created two WindowSurface (WPF), and I want to navigate betwen them. I've
I have created two tables & inserted values as shown below . Table 1
I have created two Pages Page1.xaml and Page2.xaml in windows8 metro apps. I have
I have created two DbContexts, one is for application configuration, the second is for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.