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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:20:17+00:00 2026-05-28T06:20:17+00:00

This is a simple bubble sort using a function pointer for ascending or descending.

  • 0

This is a simple bubble sort using a function pointer for ascending or descending. I don’t understand how the return statement on the ascending/descending function affects the swap.

Maybe I’m reading the return statement wrong on ascending? Does it mean return b if it’s less than a? Or does it mean return 0 or 1 if the statement is true? Could use some clarification. Thanks.

void bubble( int work[], const int size, int (*compare)(int a, int b)){
    int pass; /* pass counter */
    int count;

    void swap(int *element1Ptr, int *element2Ptr);

    for ( pass = 1 pass < size; pass++){

    /* loop to control number of comparison per pass */
        if ((*compare)(work[count], work[count+1])){
        swap(&work[count], &work[count + 1]);
     }
  }

 }

void swap ( int *element1Ptr, int *element2Ptr){
   int hold;
   hold = *element1Ptr;
   *element1Ptr = *element2Ptr;
   *element2Ptr = hold;
 }

/* determine whether elements are out of order for an ascending order sort */
 int ascending( int a, int b){
    return b < a;
  }

int descending( int a, int b){
    return b > a
 }
  • 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-28T06:20:17+00:00Added an answer on May 28, 2026 at 6:20 am

    A return statement in C returns the expression given, casted to the return type of the function (if possible). In these cases, b < a and a < b are boolean expressions, which return 1 or 0.

    In other terms, it essentially means the following, but more concise (for b < a):

    if (b < a) {
        return 1;
    }
    else {
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am implementing the simple bubble sort algorithm using CUDA, and i have a
Since I'm beginner in J I've decided to solve a simple task using this
Howdy, I do know how to implement a simple bubble-sort for 1dimensional array. But
I am trying to sort an array of integers in MIPS using bubble sort
I think this should be simple. Say I've got the following jQuery: $someForm.live('submit', function(event)
I am trying to write a simple bubble sort in Common Lisp (also works
This simple code is not producing any sound on a couple of machines that
This simple example fails to compile in VS2K8: io_service io2; shared_ptr<asio::deadline_timer> dt(make_shared<asio::deadline_timer>(io2, posix_time::seconds(20))); As
This simple regex matching returns a string instead of an object on every browser
This simple Python method I put together just checks to see if Tomcat is

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.