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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:29:07+00:00 2026-05-29T23:29:07+00:00

Ok, so I have a program with a part that I need to Order

  • 0

Ok, so I have a program with a part that I need to “Order the words such that the last letter of each item in the list is the first letter of the next item, a sort of chain of words linked together by last and first letters.”

The sample input is dog,elephant,giraffe,rhinoceros,tiger
and the correct output is dog,giraffe,elephant,tiger,rhinoceros
while my output is tiger, rhinoceros, dog, giraffe, elephant.

The comparator is this:

class linkedSort implements Comparator {
    //will return 1 for a match
    //returns 0 if no match

    public int compare(Object t, Object t1) {
        char[] charArr1 = t.toString().toCharArray();
        char[] charArr2 = t1.toString().toCharArray();

        if (charArr1[charArr1.length - 1] == charArr2[0]) {
            return -1;
        } else {
            return 1;
        }
    }
}

Any help would be much appriciated!!

  • 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-29T23:29:09+00:00Added an answer on May 29, 2026 at 11:29 pm

    You cannot solve this with a simple comparator and a sort, because the comparison does not define a total order. A total order is one in which the following four properties hold:

    • Reflexivity: x ≤ x is always true.
    • Antisymmetry: If x ≤ y and x ≠ y, then y ≤ x is never true.
    • Transitivity: If x ≤ y and y ≤ z, then x ≤ z
    • Totality: For any x and y, at least one of x ≤ y and y ≤ x holds.

    Your order is a not total order. First, it breaks reflexivity: for example, “a” ≤ “a”. Second, it breaks antisymmetry: “ease” ≤ “eve” and “eve” ≤ “ease.” Third, it breaks transitivity: “east” ≤ “tea” and “tea” ≤ “aver”, but “east” ≤ “aver” is false. Finally, it is not total: “east” is not less than “west” and “west” is not less than “east.”

    To solve this problem, you will need to approach it differently. As a hint, you may want to think of the problem as a graph where the letters are nodes and the words are edges connecting the start and end letters. Can you find a path in this graph that visits every edge exactly once?

    Hope this helps!

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

Sidebar

Related Questions

I have to write a program that sniffs network packets (part1-the simple part). And
I need to have a long descriptive dialog in part of my program and
As part of an assignment I need to create a shipping program that checks
I have a program that needs to repeatedly compute the approximate percentile (order statistic)
We have a part of our program which can save a diagnostic file for
As part of a VBA program, I have to set the background colors of
I have program that has a variable that should never change. However, somehow, it
I have program, that must interact with a console program before my program can
I have program that runs fast enough. I want to see the number of
I have a program that spits out both standard error and standard out, and

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.