Question

In: Computer Science

in java A NavigableSet is a set that stores it’s element in order. Say we have...

in java

A NavigableSet is a set that stores it’s element in order. Say we have a bunch of items
and we want to store them in order but we don’t want any duplicates. Write a generic
class that implements a structure that does that.

Solutions

Expert Solution

Here is the java program to store elements in order and elements will be printed without duplicates.

import java.util.Scanner;
public class AOrder{
   public static void main(String args[])
   {
      
       int n,temp;
       Scanner s = new Scanner(System.in);
       System.out.print("Enter no.of elements you want in array:");
       n = s.nextInt();
       int a[] = new int[n];
       System.out.println("Enter all the elements:");
       for (int i=0; i<n; i++)//Loop to store bunch of elements
       {
           a[i] = s.nextInt();
       }
       for (int i=0; i<n; i++)
       {
           for (int j=i + 1; j<n; j++)
           {
                if (a[i] > a[j])//to store elements in ascending order
                {
               temp = a[i];
               a[i] = a[j];
               a[j] = temp;
                }
           }
       }
       for (int i=0; i<n; i++)
       {
           if(i==0)//to print first element
           System.out.print(a[i] + " ");
           if(i>0&&a[i]!=a[i-1])//to check duplicates
           System.out.print(a[i] + " ");
       }
   }
}


Related Solutions

Let A be a set of real numbers. We say that A is an open set...
Let A be a set of real numbers. We say that A is an open set if for every x0 ∈ A there is some δ > 0 (which might depend on x0) such that (x0 − δ, x0 + δ) ⊆ A. Show that a set B of real numbers is closed if and only if B is the complement of some open set A
in java we need to order a list , if we create a program in java...
in java we need to order a list , if we create a program in java what  are the possible ways of telling your program how to move the numbers in the list to make it sorted, where each way provides the required result. list the name of sorting with short explanation
We say that a set of system specifications is consistent if there is a way for...
We say that a set of system specifications is consistent if there is a way for all the specifications to be simultaneously true. Otherwise, the set of specifications is inconsistent. Consider the following set of system specifications: If the file system is not locked, then new messages will be queued. The file system is not locked if and only if the system is functioning normally. If new messages are not queued, then they will be sent to the message buffer....
Write a java application that will read a set of values from the user and stores...
Write a java application that will read a set of values from the user and stores them in array a[]. The application should ask the user for the number of values he will enter. You need to do the following methods: 1. Read: This method will read n values from the user and store them in an array a 2. Print: this method will print the array as given in the sample output 3. maxEven: This method will find the...
Let G be a group of order 40. Can G have an element of order 3?
Let G be a group of order 40. Can G have an element of order 3?
In Java The Order class should have:  Seven instance variables: the order number (an int),...
In Java The Order class should have:  Seven instance variables: the order number (an int), the Customer who made the order, the Restaurant that receives the order, the FoodApp through which the order was placed, a list of food items ordered (stored as an array of FoodItem), the total number of items ordered (an int), and the total price of the order (a double).  A class constant to set the maximum number of items that can be ordered...
What do we mean when we say we have a “distribution of mean differences”? Theoretically, how...
What do we mean when we say we have a “distribution of mean differences”? Theoretically, how would you construct a “distribution of mean differences”?
Let's say that we have two variables X and Y. We calculate their correlation value to...
Let's say that we have two variables X and Y. We calculate their correlation value to be r = -.8012. What is the interpretation of this value?
Company spokespeople are often heard to say, "We have to be in that market". What is...
Company spokespeople are often heard to say, "We have to be in that market". What is a likely explanation for this statement if the market is (a) China; (b) Germany; (c) Brazil; (d) Japan; (e) the United States? I’m 350 words, Give examples of products or services.
JAVA /**    * posOfLargestElementLtOeT returns the position of the largest element in the    *...
JAVA /**    * posOfLargestElementLtOeT returns the position of the largest element in the    * array that is less than or equal to the limit parameter if all values are    * greater than limit, return -1;    *    * Precondition: the array is nonempty and all elements are unique. Your    * solution must go through the array exactly once.    *    * <pre>    * 0 == posOfLargestElementLtOeT(3, new double[] { -7 }) // value:-7...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT