Skip to main content

Java - Data Structure (part 1)

A stack allows access to only one data item: the last item inserted. If you remove this item, then you can access the next-to-last item inserted, and so on.
To insert a data item on the stack is called Push, and to remove a data item from the top of the stack is called Pop(take item from top of the stack) . Peek is sometimes useful to be able to read the value from the top of the stack without removing it.

usage: reverse the words; delimiter Matching- the delimiters are the braces '{] and '}, brackets '[' and ']', and parentheses '(' and ')'. Each opening or left delimiter should be matched by a closing or right delimiter;  e.g. a{b[c]d}e

The word queue is British for line, "queue up" means to get in line. Queue is similar to a stack, except that in a queue the first item inserted is the first to be removed(FIFO), while in a stack, the last itme inserted is the first to be removed(LIFO). Methods include insert, remove,peek, isEmpty, isFull and size().

Postfix Notation: everyday arithmetic expression are written with an operator placed between two operands. this is called infix notation, because the operator is written inside the operands. In posifix notation(Which is also called Reverse Polish Notation,or RPN), the operator follows the two operands. thus
A+B-c becomes AB+C-
A*(B+C) becomes ABC+*
(A+B)*(C-D) becomes AB+CD-*
The rules of translate infix to postfix,
1.read from left to right, looking at each character in turn. As you go along, you copy these operands and operators to the postfix output String.
2. if the character in the infix string is an operand, you copy it immediately to the postfix string. you copy the operands as you get to them, no matter how long you must wait to copy their associated operators.
3. Whenever you could have used the operator to evaluate part of the infix expression, you instead copy it to the postfix string.

Implement in Java:
Item read from Input(infix):
Operand -> Write it to output(postfix)
Open parenthesis ( -> push it on stack
close parenthesis ) -> While stack not empty, repeat the following: Pop an item, if item is not (, write it to output


2. when you've read enough to evaluate two operands and an operator, you do the calculation and substitute the answer for these two operands an operator.
3 .both * and / have a high percedence than + and - unless parentheses dictate otherwise).

In a Linked list, each data item is embedded in a link, each link object contains a reference(usually called next) to the next link in the list. You can't access a data item directly and you must use relationships between the items to locate it.

Iterators: suppose you wanted to traverse a list, performing some operation on certain links. It's far more efficient to step from link to link, checking if each one meets certain criteria and performing the appropriate operation if it does.

ADT(Abstract Date Type) is a data-storage class considered without reference to its implementation. Stacks and Queues are ADTS. They can be implemented using either arrays or linked list.



Comments

Popular posts from this blog

Stretch a row if data overflows in jasper reports

It is very common that some columns of the report need to stretch to show all the content in that column. But  if you just specify the property " stretch with overflow' to that column(we called text field in jasper report world) , it will just stretch that column and won't change other columns, so the row could be ridiculous. Haven't find the solution from internet yet. So I just review the properties in iReport one by one and find two useful properties(the bold highlighted in example below) which resolve the problems.   example:
<band height="20" splitType="Stretch"> <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true"> <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="192" y="0" width="183" height="20"/> <box leftPadding="2"> <pen lineWidth="0.25"/> …

JasperReports - Configuration Reference

Spring - Operations with jdbcTemplate

This class manages all the database communication and exception handling using a java.sql.Connection that is obtained from the provided DataSource. JdbcTemplate is a stateless and threadsafe class and you can safely instantiate a single instance to be used for each DAO.


Use of Callback Methods
JdbcTemplate is based on a template style of programming common to many other parts of Spring. Some method calls are handled entirely by the JdbcTemplate, while others require the calling class to provide callback methods that contain the implementation for parts of the JDBC workflow. This is another form of Inversion of Control. Your application code hands over the responsibility of managing the database access to the template class. The template class in turn calls back to your application code when it needs some detail processing filled in. These callback methods are allowed to throw a java.sql.SQLException, since the framework will be able to catch this exception and use its built-in excepti…