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 692425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:38:59+00:00 2026-05-14T02:38:59+00:00

Can you tell me what’s wrong with my method? I ends up putting the

  • 0

Can you tell me what’s wrong with my method? I ends up putting the same thing everywhre and it’s actually not sorting.

void sortArrays(){

    int i, j;



    for(i=0; i<counter; i++){



        for( j=0; j<i; j++){

            if( strcmp(title_arr[i], title_arr[j]) < 0){

                char* title_temp = title_arr[i];

                title_arr[j] = title_temp;





            }

        }

    }
  • 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-14T02:38:59+00:00Added an answer on May 14, 2026 at 2:38 am

    This:

    char* title_temp = title_arr[i];
    
    title_arr[j] = title_temp;
    

    Is equivalent to:

    title_arr[j] = title_arr[i];
    

    You never swap them, you just copy one to the other. You should add this line:

    title_arr[i] = title_arr[j];
    

    In between the two. That way, you’ll overwrite [i] with [j], but _temp still holds the old value of [i], so you can copy that value into [j], thus swapping them.

    I suppose it’s also a time for a lesson on algorithms. Your algorithm is known as a “bubble sort” algorithm. It is known for it’s simplicity, but in a realistic setting it is known for it’s inefficiency (the technical term is “teh sux”, and the real technical term is O(n^2) (“N squared”) performance). Some more common (and more efficient) algorithms include Quicksort, merge sort, and Heapsort, among many others. For more about measuring algorithmic scalability, see the article on Big Oh notation.*

    But, as vava pointed out in a comment, unless your assignment is to write your own sorting function, you’re going to get better performance with qsort (in C) or std::sort (in C++).

    int mystrsort(const void *a, const void *b)
    {
        return strcmp(*(const char **)a, *(const char **)b);
    }
    
    // later:
    qsort(title_arr, sizeof title_arr / sizeof(char *), sizeof(char *), mystrsort);
    

    I’m not going to stab at std::sort, but it’s going to work about the same (perhaps easier).**

    *Note that anyone who likes is free to change these Wikipedia links to Stack Overflow links. It would be better to link to SO, I just linked to Wikipedia because I knew how to find the info I needed faster.
    **Note that anyone who likes is free to add a std::sort example. I’m just not sufficiently familiar with C++.

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

Sidebar

Related Questions

As far as I can tell, inplace_merge does the exact same thing as sort,
Anyone can tell me what I'm doing wrong? I am creating a simple system
Hi hope someone can tell me what I am doing wrong with my Key
From what I can tell, this is not possible, but I wanted to ask
From what I can tell there is not way of telling if the drop
As far as I can tell, all GUI toolkits are basically the same. They
Google says that you can tell it to not provide a cached link in
Wondering if anyone can tell me how to use the Apache Lucene method 'valueOf(String)'
From what I can tell Date and DateTime have the same functionality. Is there
We can tell bots to crawl or not to crawl our website in robot.txt.

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.