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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:38:28+00:00 2026-05-31T13:38:28+00:00

My problem is that I have two functions and one of the functions calls

  • 0

My problem is that I have two functions and one of the functions calls the other and because it does this several of times(rec), i want to save the value im getting in the second function (callled Mergesort in my case). I’m actually sorting a list using Merge Sort, but im interested in knowing the amount of inversions, so I want to return an int, but i dont see how I can store the value, so i can plus all the values together in the end to get the amount of inversions (yes i know there exists a O(n^2) algorithm to find this). I suppose most of u know the MergeSort algorithm so im not going to write it all up, but from the below code u might get an idea of what im looking for. if it doesnt help, then try to answer my question from what i explained above 🙂

public ArrayList MergeMerge(ArrayList A, int e, int a){
     s=...;
     MergeMerge(A,e,a);
     MergeMerge(A,e-1,a);
     MergeSort(A,e,r,s);

public ArrayList Mergesort (ArrayList A, int e, int a, int s) {
     ...
     int inversions=0;
     for (....)
         ....
         else {
            ...
            inversions=inversions+(s-i);
            }
  • 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-31T13:38:28+00:00Added an answer on May 31, 2026 at 1:38 pm

    You can use return values to keep track of this. Here’s a generic example:

    int myRecursiveMethod() {
    
        ...
    
        // Base case
        if (someCondition) { return 1; }
    
        // Otherwise
        return myRecursiveMethod() + myRecursiveMethod() + 1;
    }
    
    
    int totalCount = myRecursiveMethod();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered a problem in my application. I have two forms, one that
I have two function, one function is a reload function that does a ajax
I have a code comprised of two functions one that reads data and the
I have this code where I am using two javascript functions that do some
I have two functions, one that creates a table like so: function return_formatted_results(result_no,addy,title,own_comment) {
Problem I have computed a probability density function that depends on two variables. I
I have a problem to create a preprocessor macro function, that concatenates two Strings
I am using DllImport in my solution. My problem is that I have two
I have two pairs of drag/drop/sortable lists using JqueryUI.http://jqueryui.com/demos/sortable/ My problem is that I
Here is the problem: I have two columns in a table that, for each

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.