www.fatihkabakci.com

Personal Website and Computer Science TUR EN

JAVA JCF TREESET

Last update: 10/3/2014 6:31:00 PM

Yazan:Fatih KABAKCI

TreeSet' ler Koleksiyon Mimarisinde verileri ağaç mekanizması ile depolayan ve arama işlerimde çok hızlı çalışan koleksiyon yapılarıdır. Binary Tree modelinde olduğu gibi verileri artan sırada depolama yapısına sahiptir. Özellikle NavigableSet arabiriminden aldığı felsefe ile bu elemanlar arasındaki büyüklük-küçüklük ayrımı ile kolaylıkla kümeler çıkarabilir.

TreeSet'lerin genel tanım aralığı aşağıdaki gibidir.

public class TreeSet extends AbstractSet implements , Cloneable, Serializable

TreeSetler' in etkisini büyük veriler ile çalıştığınız zaman görebilirsiniz. Bir TreeSet eleman ekleme algoritmasını Binary Search mantığı ile de düşünebilirsiniz. Aşağıda bu koleksiyon sınıfının örnek bir kullanımı gösterilmektedir.




Yukarıdaki programda ilk olarak sırasıyla 3, 1, 4, 0, -2, 2 elemanları ağaca eklenmektedir. Bu ekleme aşağıdaki şekilde gibidir.

       +3
   +1
     +4
    0
 -2
   +2
Önceden de bahsedildiği gibi esasen bu verilerin sırası -2, 0, 1, 2, 3, 4 şeklindedir. TreeSet sınıfının NavigableSet arabiriminden uyguladığı metotlar yukarıdaki programda mevcuttur. ceiling() ile ağaç içerisinden -1 den büyük veya eşit en küçük değer elde edilir. floor() ise tam tersi olarak ağaç içerisinden -1 den küçük veya eşit en büyük değeri elde eder. Yukarıdaki programda higher() ve lower() sırasıyla 1 den bir büyük ve bir küçük değerleri elde eder(2,0).

TreeSet' ler Set arabirimini uyguladığı için aynı zamanda birer Küme olarak nitelendirilirler. Dolayısı ile bir TreeSet' den baş, orta ve son olmak üzere çeşitli alt kümeler elde edilebilir.
  1. HeadSet()
  2. SubSet
  3. TailSet()
Bu metotların overload versiyonları inclusive boolean tipli parametreleridir. Bu parametre ilgili aralıkta başlangıç veya bitiş olarak belirtilen değerin dahil edilip edilmeyeceğini belirtir.

Yukarıdaki programda ts.headSet(1,false) ifadesi ile küme içerisinde 1' den öncekilerin alt kümesi elde edilir(-2,0). Fakat hemen sonra çağrılan ts.headSet(1,true) ile de '1 dahil baştakileri getir' denilir. subSet ve tailSet metotlarıda aynı mantık ile orta ve sondan alt kümeler elde eder.

Yukarıdaki programın ekran çıktısı ise aşağıda verilmektedir.


There has been no comment yet

Name:


Question/Comment
   Please verify the image




The Topics in Computer Science

Search this site for





 

Software & Algorithms

icon

In mathematics and computer science, an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning.

Programming Languages

icon

A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. It can be used to create programs to control the behavior of a machine. Java,C, C++,C#

Database

icon

A database is an organized collection of data. The data are typically organized to model aspects of reality in a way that supports processes requiring information.

Hardware

icon

Computer hardware is the collection of physical elements that constitutes a computer system. Computer hardware refers to the physical parts or components of a computer such as the monitor, memory, cpu.

Web Technologies

icon

Web development is a broad term for the work involved in developing a web site for the Internet or an intranet. Html,Css,JavaScript,ASP.Net,PHP are one of the most popular technologies. J2EE,Spring Boot, Servlet, JSP,JSF, ASP

Mobile Technologies

icon

Mobile application development is the process by which application software is developed for low-power handheld devices, such as personal digital assistants, enterprise digital assistants or mobile phones. J2ME

Network

icon

A computer network or data network is a telecommunications network that allows computers to exchange data. In computer networks, networked computing devices pass data to each other along data connections.

Operating Systems

icon

An operating system is software that manages computer hardware and software resources and provides common services for computer programs. The OS is an essential component of the system software in a computer system. Linux,Windows

Computer Science

icon

Computer science is the scientific and practical approach to computation and its applications.A computer scientist specializes in the theory of computation and the design of computational systems.