Class Set Algorithms collections. reverseorder (), comparator, shuffle ()

Source: Internet
Author: User

/*

This program creates and initializes a linked list. The reverseorder () method returns a comparator function that reversely compares integer objects. The elements in the list are sorted by the comparison function and displayed. Next, call the shuffle () method to randomly arrange the list, and then display the maximum and minimum values of the list.

*/

// Demonstrate various algorithms.
Import java. util .*;
Class algorithmdemo {
Public static void main (string [] ARGs)
{
// Create and initialize linked list.
Counter list LL = new counter list ();
Ll. Add (New INTEGER (-9 ));
Ll. Add (New INTEGER (10 ));
Ll. Add (New INTEGER (-10 ));
Ll. Add (New INTEGER (9 ));
Ll. Add (New INTEGER (99 ));
Ll. Add (New INTEGER (100 ));

// Create a reverse order comparator.
Comparator r = collections. reverseorder ();

// Sort list by using the comparator.
Collections. Sort (LL, R );

// Get an iterator.
Iterator I = ll. iterator ();

System. Out. println ("list sorted in reverse :");
While (I. hasnext ()){
System. Out. println (I. Next () + "");
}
System. Out. println ();
Collections. Shuffle (LL );

// Display randomized list
I = ll. iterator ();
System. Out. Print ("list shuffled :");
While (I. hasnext ()){
System. Out. Print (I. Next () + "");
}
System. Out. println ();

System. Out. println ("minimum:" + collections. Min (LL ));
System. Out. println ("Maximum:" + collections. Max (LL ));
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.