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

  • Home
  • SEARCH
  • 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 3610592
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:46:17+00:00 2026-05-18T21:46:17+00:00

I have a program that uses (and must continue to use) an old sorting

  • 0

I have a program that uses (and must continue to use) an old sorting function implementing qsort. I must also provide the sorting function with proper data to sort data both ascending (if string contains even numbers) or descending (if string contains odd numbers).

The data must be altered to achieve this, the sorting function cannot be altered.

The code is written in C but I have no relevant code snippet for this particular problem.

The real question is:

How do I transform the data so that the output matches the desired output below?

I have the following data (or similar)

String 1
String 2
String 3
String 4
String 5
String 6

EDIT: The data is a number of strings type char **, the number within each string is an int.

The desired output is

String 5
String 3
String 1
String 2
String 4
String 6

Sorting is usually done in a descending fashion matching the input 1:1. I have managed to produce a transformation rendering the following output by prepending 1 or 0 to the numbers following the string.

So the internal data to be sorted looks like this

String 01
String 12
String 03
String 14
String 05
String 16

This produces the following output (transformation is only used in sorting, and is temporary).

String 1
String 3
String 5
String 2
String 4
String 6
  • 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-05-18T21:46:17+00:00Added an answer on May 18, 2026 at 9:46 pm

    You should have a struct which contains data, and value:

    Struct DataValue
    {
       string data;
       int value;
    } 
    

    like {"01", 1}
    Then sort by value and output data,
    sorting is not hard if you want to do usual sort:
    first sort by value to make list like what you shown. (for values)
    now create an empty array of data values (with base array size), start from last item and fill it as bellow:

        int j = 0;
        for (int i = a.Count - 1; i >= 0; i -= 2) // fill bottom of list
        {
            b[a.Count - 1 - j] = a[i];
            j++;
        }
    
        j = 0;
        for (int i = a.Count - 2; i >= 0; i -= 2)  // fill root of list
        {
            b[j] = a[i];
            j++;
        }
    

    At last output the values.

    I wrote it in c# it’s not very different in c.
    you will get:

      List<int> a = new List<int>{1,2,3,4,5,6,7};
    
       b==> 6,4,2,1,3,5,7
    
    and for:
      List<int> a = new List<int>{1,2,3,4,5,6};
      b==> 5,3,1,2,4,6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that uses JAMA and need to test is a matrix
I have a Python program that uses the threading module. Once every second, my
I have a Windows C# program that uses a C++ dll for data i/o.
I have a java client program that uses mdns with service discovery to find
I have a small command line program that uses the Team System API. When
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that spits out an Excel workbook in Excel 2003 XML
I have a program that monitors debug messages and I have tried using a

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.