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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:26:00+00:00 2026-05-15T04:26:00+00:00

For example, we have the following array: char data[]=new char[]{‘A’,’S’,’O’,’R’,’T’,’I’,’N’,’G’,’E’,’X’,’A’,’M’,’P’,’L’,’E’}; and an index array:

  • 0

For example, we have the following array:

char data[]=new char[]{'A','S','O','R','T','I','N','G','E','X','A','M','P','L','E'};

and an index array:

int  a[]=new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};

void insitu (char data[], int a[], N)
{
    for (int i=0;i<N;i++)
    {
        char v=data[i];
        int j, int k;
        for (k = i; a[k] != i; k = a[j], a[j]=j)
        {
            j=k;
            data[k]=data[a[k];
        }
        data[k]=v;
        a[k]=k;
    }
}

My question is what j should be initialized to. When I run this code, it asks me to initialize j; what should I do?

  • 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-15T04:26:01+00:00Added an answer on May 15, 2026 at 4:26 am

    This is a Java implementation of the in-place sort in Sedgewick’s Algorithms in C++ (see page):

    public class InSitu {
        public static void main(String[] args) {
            int[] a = { 0, 10, 8, 14, 7, 5, 13, 11, 6, 2, 12, 3, 1, 4, 9 };
            char[] data = { 'A', 'S', 'O', 'R', 'T', 'I', 'N', 'G',
                'E', 'X', 'A', 'M', 'P', 'L', 'E' };
            insitu(data, a, a.length);
            System.out.println(java.util.Arrays.toString(a));
            // prints "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]"
            System.out.println(java.util.Arrays.toString(data));
            // prints "[A, A, E, E, G, I, L, M, N, O, P, R, S, T, X]"
        }
        static void insitu(char[] data,int[] a, int N) {
            for (int i = 0; i < N; i++) {
                char v = data[i];
                int j, k;
                for (k=i; a[k] != i; k = a[j], a[j] = j) {
                    j = k;
                    data[k] = data[a[k]];
                }
                data[k] = v;
                a[k] = k;
            }
        }
    }
    

    On array declarations

    Please, please, do not make a habit of declaring arrays like this:

    int x[];
    

    You should instead put the brackets with the type, rather than with the identifier:

    int[] x;
    

    Related questions

    • Is there any difference between Object[] x and Object x[] ?
    • Difference between int[] myArray and int myArray[] in Java
    • in array declaration int[] k,i and int k[],i
      • These declarations result in different types for i!

    On definite assignment

    The compiler is smart enough to know when a local variable is definitely assigned, taking into account loop constructs, etc.

    The following code compiles:

            int local;
            do {
                local = 0;
            } while (local != 0);
    

    While this doesn’t:

            int local;
            while (local != 0) { // doesn't compile!
                local = 0;
            }
    

    Similarly, this compiles:

            for (int local; ; local++) {
                local = 0;
            }
    

    This is because of the semantics of for loop, where the loop body (local = 0;) precedes the loop update (local++) in the control flow, even though it may not look like it in the text.

    The specification doesn’t allow the compiler to be too smart; for example the following doesn’t compile:

        boolean b = false; // or whatever
        int local;
        if (b) {
            local = 0;
        }
        if (!b) {
            local = 1;
        }
        local++; // doesn't compile! 
    

    But this does:

        boolean b = false; // or whatever
        int local;
        if (b) {
            local = 0;
        } else {
            local = 1;
        }
        local++;
    

    See also

    • JLS 16 Definite Assignment
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following array as3 example: var arrayDefinitionsargsAmfPhp:Array = new Array(); arrayDefinitionsargsAmfPhp['tabela'] =
I have the following example code: $dataProvider = new CActiveDataProvider('firstTable', array('criteria' => array( 'select'
for example I have the following: <div class=both> <textarea data-id=1 name=t1>Value 1</textarea> <input type=checkbox
I have following structure with example data: id season_id title 1 1 Intro 2
Say, for example, I have the following array: files=( foo bar baz fizzle )
I have the following class (I've trimmed irrelevant stuff): class Example { private: char*
I have the following packet layout: struct PacketLayout { int GateCode; BYTE StringLen; char
for example I have the following: I want to go through each div class
Say for example I have the following styles: #HorizNav ul li a.active:link { background-color:
I'm trying to figure out how XSLT process namespace prefixes and have following example:

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.