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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:40:38+00:00 2026-06-07T20:40:38+00:00

My program (a decryptor that uses letter frequencies to decrypt things) has two ArrayLists

  • 0

My program (a decryptor that uses letter frequencies to decrypt things) has two ArrayLists that it uses to keeps track of letter frequencies. I paired these ArrayLists so that one (the list of characters in the input) was always linked to the other (the list of frequencies in the input) so that the character at index i in one would always correspond to the the frequency at index i in the other. I used a quicksort algorithm to sort in descending order. Here is the code for the quicksort and swap methods:

private static void quickSort(int low, int high){


    int i = low;
    int j = high;
    long middle = freqInCiphertext.get((low+high)/2);

    while (i < j) {
        while (freqInCiphertext.get(i) > middle) {
            i++;
        } //End while
        while (freqInCiphertext.get(j) < middle) {
            j--;
        }//End while
        if (j >= i) {
            swap(i, j);
            i++;
            j--;
        } // End if
    } // End while


    if (low<j) {
        quickSort(low, j);
    } else if (i<high) {
        quickSort(i, high);
    } //end if
}//End quickSort

private static void swap(int i, int j) {
int tempInt = freqInCiphertext.get(i);
String tempString = charsInCiphertext.get(i);

freqInCiphertext.set(i, freqInCiphertext.get(j));
charsInCiphertext.set(i, charsInCiphertext.get(j));

freqInCiphertext.set(j, tempInt);
charsInCiphertext.set(j, tempString);
}// End swap

However, when I run my code, it returns the array lists partially sorted, like this:

[ , e, t, a, o, n, i, h, r, d, l, u, s, m, z, q, x, j, v, k, p, f, w, c, b, y, g]
[64031, 25856, 19326, 17571, 16398, 14349, 14200, 12784, 11617, 9930, 8391, 5820, 12934, 5636, 173, 178, 312, 356, 1929, 2175, 3186, 4310, 5479, 4666, 3491, 4673, 5100]

Can anybody see any errors in the algoritm? I have tried it a couple of different ways already (like a >= instead of a >, etc.) without luck.

  • 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-07T20:40:39+00:00Added an answer on June 7, 2026 at 8:40 pm

    Since both j can be > than low and i can be < high at the same time, you don’t want to do “else if (i < high)”. That should just be in a separate if likeso:

    if (low<j) {
        quickSort(low, j);
    }
    
    if (i<high) {
        quickSort(i, high);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program in C++ that uses the cryptopp library to decrypt/encrypt messages.
Hey I'm writing a program that uses an @INC hook to decrypt the real
I am attempting to decrypt a number encrypted by another program that uses the
I'm working on a simple program that uses OpenSSL to do basic RSA encryption
I'm writing a program that, using Rijndael, will encrypt and decrypt files/folders using a
I wrote a basic UNIX program that uses some low-level I/O. Nothing special, here's
I am writing a mapreduce program that uses multiple I/O pipes (one pipe per
I'm making a program in C++ that uses 2 images to detect SURF Features,
Program that calculates and shows the value of (2 to the 10th power) This
This program builds a dictionary out of a list based on what two index

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.