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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:07:43+00:00 2026-05-12T20:07:43+00:00

i have a list 1 column and 100 rows each with a number the

  • 0

i have a list 1 column and 100 rows each with a number
the number on each row may not be unique
i need to output the unique list of numbers sorted according to their rank , which is less if the number of its repetitions is more. least ranked number i.e 1 is on the top

now here is how i am planning to solve this problem

first i want to define an array of the structure would be like this

struct abc[100]
{
int number
int occurrence = 1;
}

now i want to go through the list for each row and check if the number exist in the array of structure or not. if it does not i want to store the number in a abc[row].number however if the number exists in the array of structure i want to increment the occurrence of that particular record.

at the end i would get a array of structure filled with each unique number and number of time it occurs together as records.

Is this style of programming a good way ? defining structures and moving through them is looking a tedious job to me can you suggest me a better way ? I’m a beginner programmer please feel free to give me any sort of advice

  • 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-12T20:07:43+00:00Added an answer on May 12, 2026 at 8:07 pm

    Here is an example that returns a Map of item frequencies. The method is generic and will therefore work for any type of item, not just Integer. I’m returning a SortedMap (TreeMap implementation) and hence the function runs with complexity O(n log n). However, I could have opted for a HashMap implementation, reducing the complexity to O(n) (as insert performance for HashMap is O(1)).

    import java.util.*;
    
    public class Main {
      public static void main(String[] args) {
        List<Integer> l = new LinkedList<Integer>();
        l.add(5);
     l.add(10);
     l.add(2);
     l.add(5);
     l.add(20);
    
     System.err.println(freq(l));
      }
    
      private static <T> SortedMap<T, Integer> freq(Collection<? extends T> c) {
     SortedMap<T, Integer> ret = new TreeMap<T, Integer>();
    
     for (T t : c) {
         Integer fq = ret.get(t);
         ret.put(t, fq == null ? 1 : fq + 1);
     }
    
     return ret;
      }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a databound list view and can set all the column widths manually
I want to have CListCtrl.EditLabel() for any column of the list. How can I
I have a list, each item of which has several things in it, including
I have 100 columns in a table and I want to list 99 columns
I have a typical table, 7 columns, (paginated to 100 rows per time). What
I have a Telerik grid. For each row there is a details table. The
I have a list of urls in a grid, And I need that when
I have got a List<Problem> which I want to export to a column based
I have a varchar column conteining a code, this code could by only numbers,
I want to create a list of columns in SQL Server 2005 that have

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.