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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:45:13+00:00 2026-05-17T23:45:13+00:00

Hey, I’m trying to implement the ShellSort algorithm and now I got a problem:

  • 0

Hey, I’m trying to implement the ShellSort algorithm and now I got a problem:

warning: [unchecked] unchecked cast
found : java.util.Vector
required: java.util.Vector<java.lang.Object>
Vector<Object> vcur = (Vector<Object>)currentCols[tcur];
Same with vtmp.

I don’t know where the problem is. It would be really great if you could help me. 🙂
This is my code:

public static Vector<Object> shellSort(Vector<Object> ul) {
    int lcount = ul.size();
    int colcount = 4; // 2^x
    Vector[] currentCols = { ul };
    for(; colcount > 0; colcount = (colcount / 2)) {
        Vector[] tmpCols = new Vector[colcount];
        for(int t1 = 0; t1 < colcount; t1++) {
            tmpCols[t1] = new Vector<Object>();
        }
        int tcur = 0;
        int tcurlvl = 0;
        int ttmp = 0;
        for(int t2 = 0; t2 < lcount; t2++) {
            Vector<Object> vcur = (Vector<Object>)currentCols[tcur];
            Vector<Object> vtmp = (Vector<Object>)tmpCols[ttmp];
            vtmp.addElement((Object)vcur.elementAt(tcurlvl));

            // step to next place
            tcur++;
            ttmp++;
            if(tcur == currentCols.length) { tcur = 0; tcurlvl++; }
            if(ttmp == tmpCols.length) { ttmp = 0; }
        }
    }
    return ul;
}
  • 1 1 Answer
  • 3 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-17T23:45:13+00:00Added an answer on May 17, 2026 at 11:45 pm

    This still won’t fix the issue (you code doesn’t work… never sorts) but it is updated to use List instead of Vector (Vector is obsolete, cannot be deprecated since official APIs depend on it). Unless you need the synchronization built into Vector use List/ArrayList instead.

    I also changed the array creation to be closer to generic (cannot truly do generic array creation).

    Finally I made the whole method generic so that it can work typesafely with things other than Object (so a List or List, etc…).

    It still gives warnings though. Perhaps you should work on getting the code to work properly before you worry about this particular warning (normally I would not suggest that, but with generics that can sometimes be a better way to do it).

    public static <T> List<T> shellSort(List<T> ul) 
    {
        int lcount = ul.size();
        int colcount = 4; // 2^x
    
        List<T>[] currentCols = (List<T>[])Array.newInstance(List.class, 1);
        currentCols[0] = ul;
    
        for(; colcount > 0; colcount = (colcount / 2))
        {
            List<T>[] tmpCols = (List<T>[])Array.newInstance(List.class, colcount);
    
            for(int t1 = 0; t1 < colcount; t1++)
            {
                tmpCols[t1] = new ArrayList<T>();
            }
    
            int tcur = 0;
            int tcurlvl = 0;
            int ttmp = 0;
    
            for(int t2 = 0; t2 < lcount; t2++)
            {
                List<T> vcur = currentCols[tcur];
                List<T> vtmp = tmpCols[ttmp];
                vtmp.add(vcur.get(tcurlvl));
    
                // step to next place
                tcur++;
                ttmp++;
                if(tcur == currentCols.length) { tcur = 0; tcurlvl++; }
                if(ttmp == tmpCols.length) { ttmp = 0; }
            }
        }
    
        return ul;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey folks I am trying to implement a search functionality in a website using
Hey guys, am trying to write to do type casting in java, but i
hey guys having this really simple problem but cant seem to figure out have
Hey its really hard to define an exact title for my problem. I am
Hey guys I'm following the rails tutorial found here http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/ and I've gotten to
Hey I can't figure out an error I got. I had my App working
Hey everyone I am a newbie and would love some help. I got the
Hey trying to get a validation check working on a boolean field called 'activated'.
Hey people I've been searching over the internet for the following problem without success...
Hey all i have an XML file that i am trying to loop though.

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.