JAVA Implementation of multiple data structures (excellent)

Source: Internet
Author: User
Linked ListProgram code class node {
Object item; node next;
Node (object v ){
Item = V; next = NULL;
}
}

Header pointer, null tail pointer
Initialization: Head = NULL;
Insert t after X:
If (x = NULL)
{Head = T; head. Next = NULL ;}
Else {T. Next = x. Next; X. Next = T ;}
Remove the node after X: t = x. Next; X. Next = T. Next;
Loop traversal: For (t = head; t! = NULL; t = T. Next)

Check whether the linked list is empty: If (Head = NULL)
Short node, empty tail pointer
Initialization: Head = new node (); head. Next = NULL;
Insert T: T. Next = x. Next; X. Next = T;
Remove the node after X: t = x. Next; X. Next = T. Next;
Loop traversal: For (t = head. Next; t! = NULL; t = T. Next)
Check whether the linked list is empty: If (head. Next = NULL)
Short node, empty End Node
Initialization: Head = new node (); Z = new node (); head. Next = z; Z. Next = z;
Insert T: T. Next = x. Next; X. Next = T;
Remove the node after X: t = x. Next; X. Next = T. Next;
Loop traversal: For (t = head. Next; t! = Z; t = T. Next)
Check whether the linked list is empty: If (head. Next = z)
Cyclic linked list
First insert: head. Next = head;
Insert T: T. Next = x. Next; X. Next = T;
Remove the node after X: t = x. Next; X. Next = T. Next;
Loop traversal: t = head; do {T = T. Next;} while (T! = Head );
Check whether there is only one data item: If (head. Next = head)

Stack

Array ImplementationProgram code class Stack {
Private object [] S;
Private int N;
Stack (INT maxn ){
S = new object [maxn]; n = 0;
}
Boolean isempty () {return (n = 0 );}
Void push (Object item) {s [n ++] = item ;}
Object POP (){
Object T = s [-- N]; s [N] = NULL; return T;
}
}

Linked List Implementation
Class Stack {
Private node head;
Private class node {
Object item; node next;
Node (Object item, node next ){
This. Item = item; this. Next = next;
}
}
Stack (Object maxn) {head = NULL ;}
Boolean isempty () {return (Head = NULL );}
Void push (Object item) {head = new node (item, head );}
Object POP (){
Object v = head. item;
Node T = head. Next;
Head = T;
Return V;
}
}

Implement a linked list of FIFO queuesProgram code class queue {
Private class node {
Object item; node next;
Node (Object item ){
This. Item = item; this. Next = NULL;
}
}
Private node head, tail;
Queue (object Max) {head = NULL; tail = NULL ;}
Boolean isempty () {return (Head = NULL );}
Void put (Object item ){
Node T = tail;
Tail = new node (item );
If (empty ())
Head = tail;
Else T. Next = tail
}
Object get (){
Object v = head. item;
Node T = head. Next;
Head = T;
Return V;
}
}

I only tried these data structures. If you are interested, try other structures, such as multi-thread control.

Related books: Java data structures and algorithms (version 2)
The content in the book includes:

A visual topic discussion composed of Java-based demos to master data structures and algorithms
Learn how to select the right algorithm for common and uncommon programming conditions
Use data structures and algorithms to model real-world processing processes
Understand the strengths and weaknesses of different data structures and consider how to use them to improve programming efficiency
Learn how to simplify data structures and algorithms with Object-Oriented Programming
This book teaches you how to arrange and manipulate data in an easy-to-understand manner, including some difficult questions. Learn about this knowledge to make computer applications the best possible.
Regardless of the language or platform used, mastering the data structure and algorithms will improve the quality and performance of the program.
The book provides an original set of visual discussion topics to clarify the main topics. It uses the Java language to describe important concepts and avoids the complexity of the C/C ++ language, this allows you to focus on data structures and algorithms.
Mr. Robert lafore, an experienced author, provides many simple and clear examples to avoid lengthy and tedious mathematical proofs of such propositions. In the second version, he used the latest Java features to modify and expand his example. There are problems and exercises after each chapter, giving readers the opportunity to test their own comprehension programs.
The book introduces the data structures and algorithms used in computer programming. It provides an in-depth explanation of how to operate and manage data in computer applications to achieve optimal performance.
The book consists of 15 chapters, which cover basic concepts, arrays, simple sorting, heap and queue, linked list, recursion, advanced sorting, binary tree, red/black tree, hash table, and graphics. The appendix provides special program and routines, related books and answers.
Java data structure and algorithm (second edition) is a Chinese version with an English version.
All source code in the book can be obtained from the web site:
Http://www.samspublishing.com/download
You can also download the source code of Java data structures and algorithms (version 2.
Http://www.jspcn.net/software/20058313/15768.rar

Java data structure and object-oriented programming Basics
The book uses Java GUI programming as the description method, UML as the modeling tool, and the Object-Oriented Programming Method to Study the classical data structure. Java data structure and object-oriented programming basics are divided into two parts and 18 chapters. The first part is Chapter 1st to chapter 8, which introduces the object-oriented programming methods and Java GUI programming methods. The second part consists of chapters 9th to 18, which focuses on some classic data structures and is equipped with well-designed experimental programs to enhance the reader's understanding of the basic concepts and principles. The appendix introduces the simple concepts of UML and algorithm complexity, as well as the installation and use of the foundations class library used in this book.
Java data structure and object-oriented programming basics is the latest teaching material used to learn the classic data structure in Java. It is suitable for students of computer science in colleges and universities to read, it is also suitable for software developers who want to improve Java Oop, Gui programming, and data structure.
 

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.