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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:54:12+00:00 2026-05-25T19:54:12+00:00

I found a bunch of java files online and there is one function that

  • 0

I found a bunch of java files online and there is one function that appears all over the place but i cannot find the definition of on google: compex. google keeps on sending me to complex, no matter how i use symbols to make compex an important search term. it doesnt seem to be imported from anywhere. all i have managed to find out about it is that it takes 2 single integers as inputs.

i am not a java programmer. im just trying to figure out what in the world the code means

/*
 * PermSortAlgorithm.java
 * Patrick Morin takes no responsibility for anything. So there.
 *
 */

/**
 * A PermSort Demonstration algorithm.  The PermSort algorithm is due
 * to Patrick Morin <http:www.scs.carleton.ca/~morin>.  The algorithm
 * works by trying every permutation until it finds one that's
 * sorted.  That's right, there are n! permutations and it takes O(n)
 * time to test each one, yielding an O(nn!) algorithm.  No hate mail
 * please.
 *   
 * @author Patrick Morin 
 */
class PermSortAlgorithm extends SortAlgorithm {


    /**
     * Check if the input is sorted.  Do it in a weird way so it looks
     * good for the sort demo.
     */
    boolean issorted(int a[], int i) throws Exception {
    for (int j = a.length-1; j > 0; j--) {
        compex(j, j-1);
        pause();
        if(a[j] < a[j-1]) {
        return false;
        }
    }
    return true;
    }

    /**
     * Privately sort the array using the PermSort algorithm.
     */
    boolean sort(int a[], int i) throws Exception {
    int j;

    // Check if array is already sorted
    if (issorted(a, i)) {
        return true;
    }

    // Array wasn't sorted so start trying permutations until we
    // get the right one.
    for(j = i+1; j < a.length; j++) {
        compex(i, j);
        pause();
        int T = a[i];
        a[i] = a[j];
        a[j] = T;
        if(sort(a, i+1)) {
        return true;
        }
        T = a[i];
        a[i] = a[j];
        a[j] = T;
    }
    return false;
    }

    /** 
     * Sort the input using the  PermSort algorithm.
     */
    void sort(int a[]) throws Exception {
    sort(a, 0);
    }
}
  • 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-25T19:54:13+00:00Added an answer on May 25, 2026 at 7:54 pm

    It’s short for compare-and-exchange.

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

Sidebar

Related Questions

In Java there are a bunch of methods that all have to do with
I found this open-source library that I want to use in my Java application.
I found a bunch of possible duplicates around this but none really seemed to
I found a bunch of other questions about this topic, but for some reason
I've found a bunch of questions that were very close to what I need.
Can someone please correct me, I've found this example online and bunch of others
I have been researching FRP and found a bunch of different implementations. One model
I have gone through a bunch of question posts, and found one person with
I found a bunch of scripts in the project I have been newly assigned
Anyone know what this error means? after googling I found a bunch of sites

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.