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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:35:27+00:00 2026-05-27T20:35:27+00:00

I need a way to represent information about Weeks and Days as such: W1:

  • 0

I need a way to represent information about Weeks and Days as such:

W1: D1,D2
W2: D1,D5
W3: D3,D2

so that, given my current week and day, I should be able to get the previous day and next day

For ex:

if(currentDay = W2D5)
{
    prevDay = W2D1;
    nextDay = W3D3;
}

Here are two options I came up with:

  1. Use a treemap

    TreeMap< Integer,TreeMap< Integer>>

In the outer tree map, store the week number as the key and in the inner tree map, store the

  1. Use an array
    [w1d1,w2d2,w2d1…]

What would be a good data structure to use for such a problem?

  • 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-27T20:35:28+00:00Added an answer on May 27, 2026 at 8:35 pm

    Why not just a well-ordered collection on a WeekDay type? (The WeekDay type includes a Week and a Day and provides well-defined ordering.)

    If this were the case, TreeSet<WeekDay> could be used with higher/lower (or even headSet/tailSet).

    TreeSet<WeekDay> days = ...;
    WeekDay nextDay = days.higher(currentDay);
    

    Unfortunately TreeSet<WeekDay> (or PriorityQueue) and other standard data-types won’t work because they lack a method of iterating forward/back from a given element. This isn’t strictly true, at least TreeMap can be used, just with a O(1) manual look-up using the iterator: however, the required operations to take advantage of the O(lg n) access just aren’t “standard” in a TreeSet.

    This article on Sorted Lists in Java covers a bunch of interesting things, as well as providing an implementation which could be adapted.

    Of course, it is also possible to just use an ArrayList and keep it sorted on update. In that case a Collections.binarySearch can be used and the index for prev/next are easily provided 🙂

    Happy coding.

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

Sidebar

Related Questions

I need to represent single precision numbers as text in a way that won't
I need a way to represent a 2-D array (a dense matrix) of doubles
I need a way for a single variable to represent two kinds of objects
I need a way to bind POJO objects to an external entity, that could
I need to represent graph information with relational database. Let's say, a is connected
Greetings, I need to be able to drag and drop items that's contained in
Need a way to allow sorting except for last item with in a list.
I need a way to get the friend ids of a user. I written
I need a way to easily export and then import data in a MySQL
I need a way to recursively delete a folder and its children. Is there

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.