RSS2.0

Looking Something??



[Data Structure] Circularly Linked List - Java Programming Language

Saturday, August 9, 2008

Circularly-Linked List


A variant of a linked list in which the first and final nodes are linked together. This can be done for both singly and doubly linked lists. To traverse a circular linked list, you begin at any node and follow the list in either direction until you return to the original node. Viewed another way, circularly-linked lists can be seen as having no beginning or end. This type of list is most useful for managing buffers for data ingest, and in cases where you have one object in a list and wish to see all other objects in the list. The pointer pointing to the whole list may be called the access pointer.

[ Read More ]


[Data Structure] Doubly Linked List - Java Programming Language

Friday, July 18, 2008

Doubly-Linked List

A variant of a linked list in which each node has two links : one points to the previous node, or points to a null value or empty list if it is the first node; and one points to the next node, or points to a null value or empty list if it is the final node. This allows easily accessing list items backward as well as forward and deleting any item in constant time.

[ Read More ]


[Data Structure] Singly Linked List - Java Programming Language

Thursday, March 6, 2008

Singly-Linked List

Each item called Node in the Singly linked list is stored with an indication of where the next item is. To access the data in the middle of the list, head, which is the first node, is used to know where the first item is. Different with array, a linked list allows addition or deletion of items in the middle of collection with only a constant amount of data movement. To conclude, The list will be a chain of objects of type Node that contain the data and a reference to the next Node in the list.

The implementation of class Singly Linked List in Java Programming Language :

class Node{

int data;

Node next;

}

class LinkedList{

Node head; //posisi awal dari linked list

Node tail; //posisi akhir dari linked list

/**

* Fungsi untuk mengecek apakah linked list masih kosong

*/

boolean isEmpty(){

return (head==null);

}

void addFirst(Node input){

if (isEmpty()){ //Jika linked list masih kosong,

head = input; //maka head dan tail sama dengan node input

tail = input;

}

else {

input.next = head; //Jika linked list sudah berisi,

head = input; //maka input akan di depan dan menjadi head

}

}

void addLast(Node input){

if (isEmpty()){ //Jika linked list masih kosong,

head = input; //maka head dan tail sama dengan node input

tail = input;

}

else {

tail.next = input; //Jika linked list sudah berisi,

tail = input; //maka input akan di belakang dan menjadi tail

}

}

void insertAfter(int key,Node input){

Node temp = head;

do {

if (temp.data == key){ //Jika data sama dengan key, maka input

input.next = temp.next; //disambung diantara temp dan temp.next

temp.next = input;

System.out.println("Insert data is succeed.");

break; //dari temp --> temp.next menjadi :

} //temp --> input --> temp.next

temp = temp.next;

}

while (temp!=null);

}

void insertBefore(int key,Node input){

Node temp = head;

while (temp != null){

if ((temp.data == key)&&(temp == head)){

this.addFirst(input); /* jika insert pada awal linked list

maka call method addFirst */

System.out.println("Insert data is succeed.");

break;

}

else if (temp.next.data == key){

input.next = temp.next; //dari temp --> temp.next menjadi

temp.next = input; //temp --> input --> temp.next

System.out.println("Insert data is succeed.");

break;

}

temp = temp.next;

}

}

void removeFirst(){

Node temp = head;

if (!isEmpty()){

if (head == tail){ //jika element linked list hanya 1,

head = tail = null; //maka head dan tail menjadi null

} //sehingga linked list kosong

else {

temp = temp.next; //memajukan temp ke temp.next

head = temp; //kemudian head dipindah ke temp

temp = null; //kemudian temp di-null (optional)

}

}

else System.out.println("Data is empty!");

}

void removeLast(){

Node temp = head;

if (!isEmpty()){

if (tail == head){ //jika element linked list hanya 1

head = tail = null; //maka head dan tail menjadi null

} //sehingga linked list kosong

else {

while (temp.next != tail){

temp = temp.next; //memajukan temp hingga satu elemen

} //sebelum tail.

temp.next = null; //temp.next di-null,dan jadi akhir LL

tail = temp; //tail dipindah ke temp

temp = null;

}

}

else System.out.println("Data is empty!");

}

void remove(int key){

Node temp = head;

if (!isEmpty()){

while (temp != null){

if (temp.next.data == key){ //mengganti temp.next dengan

temp.next = temp.next.next; //temp.next.next

break; //dari temp --> temp.next -->temp.next.next

} //menjadi temp --> temp.next.next

else if ((temp.data == key)&&(temp == head)){

this.removeFirst();//jika key berada pada awal linked list,

break; //maka call method removeFirst

}

temp = temp.next;

}

} else System.out.println("Data is empty!");

}

void find (int key){

int i = 0;

boolean found = false;

Node temp = head;

while (temp != null){

if (temp.data == key){

found = true;

break;

}

i++;

temp = temp.next;

}

if (found){

System.out.println(key+" is found at index "+i);

}

else System.out.println("Data isn't found");

}

void printNode(){

Node temp;

temp = head;

while (temp != null){

System.out.println(temp.data);

temp = temp.next;

}

}

}

[ Read More ]


[Java] Linked List - Introduction - Data Structures

Linked List - Introduction

A Linked List is a concrete data structure consisting of a sequence of nodes, each containing arbitrary data fields and one or two references ("links") pointing to the next and/or previous nodes.

The principal benefit of a linked list over a conventional array is that the order of the linked items may be different from the order that the data items are stored in memory or on disk, allowing the list of items to be traversed in a different order.

A linked list is a self-referential data type because it contains a pointer or link to another node of the same type.

Linked lists permit insertion and removal of nodes at any point in the list in constant time, but do not allow random access like array.

Several types of linked list :

  1. Singly-Linked List
  2. Doubly-Linked List
  3. Circularly-Linked List

a. Single-Circularly-Linked List

b. Double-Circularly-Linked List

[ Read More ]


[Java] Array - Java Programming Language

Array – Java Programming Language

Array Declaration and Initialization :

a) 1 Dimensional Array :

Declaration : |data type|[ ] |variable name|;

|data type||variable name|[ ];

Example : int x[ ]; /* or */ int [ ] x;

Initialize Array / Instansiate Object with constructor :

|variable name|= new |data type|[sum_of_array];

Example : x = new int[10];

We can also write these together :

|data type||variable name|[ ] = new |data type|[sum_of_array];

Example : int x[ ] = new int [10];

b) 2 Dimensional Array :

Declaration : |data type|[ ][ ] |variable name|;

|data type||variable name|[ ][ ];

Example : int x[ ][ ]; /* or */ int [ ][ ] x;

Initialize Array / Instansiate Object with constructor :

|variable name|= new |data type|[sum_of_array][sum_of_array];

Example : x = new int[10][10];

We can also write these together :

|data type||variable name|[ ] = new |data type|[sum_of_array] [sum_of_array];

Example : int x[ ][ ] = new int [10][10];

[ Read More ]


[Java] Simple Java Coding - Hello World!

Monday, March 3, 2008

Simple Java Coding – Hello World!

What’s wrong with the program below?

public class Main

{

void show(){

System.out.println("Hello World!");

}

public static void main (String args[])

{

int value;

show();

System.out.println(value);

}

};

The answer :

  1. the value of variable int value isn’t initialized yet
  2. Method which has static access modifier can only call method which type is static

Correction :

public class Main

{

static void show(){

System.out.println("Hello World!");

}

public static void main (String args[])

{

int value = 0;

show();

System.out.println(value);

}

};

This program will run well. Try it to make a simple java program.


[ Read More ]


[Java] Simple Java Programming Language Keywords

Simple Java Keywords

a) new : Produce a single instans from a class dan make reference to that object.

Example :

class box {

int w,h,l;

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

public class BoxData {

public static void main(String[] args) {

box k = new box();

//k is a reference to an object of box class

}

}

b) private: Give a special access to a class so it can only be used by its class.

Example :

class box {

int w,h,l;

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

//w,h,and l variable can only be used by class Box

c) public : Give a special access to a class so it can be used by all classes.

Example :

class box {

int w,h,l;

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

//class box can be accessed by all classes include different package.

d) this : A special referenced symbol used in a method accessed by active object.

Example :

class box {

int w,h,l;

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

e) protected: Give a special access to a class so it can be used by a method which is in that class and subclass elements.

Example :

class box {

protected int w,h,l;

protected getW(){

return this.w;

}

box() {

this.w = 0;

this.h = 0;

this.l = 0;

}

};

[ Read More ]


[Java] Introduction to Java Programming Language

Introduction to Java Programming Language

Java is a programming language originally developed by Sun Microsystems and released in 1995 as a core component of Sun's Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode which can run on any Java virtual machine (JVM) regardless of computer architecture.

The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun made available most of their Java technologies as free software under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Classpath.

HISTORY

The Java language was created by James Gosling in June 1991 for use in a set top box project. The language was initially called Oak, after an oak tree that stood outside Gosling's office - and also went by the name Green - and ended up later being renamed to Java, from a list of random words. Gosling's goals were to implement a virtual machine and a language that had a familiar C/C++ style of notation. The first public implementation was Java 1.0 in 1995. It promised "Write Once, Run Anywhere" (WORA), providing no-cost runtimes on popular platforms. It was fairly secure and its security was configurable, allowing network and file access to be restricted. Major web browsers soon incorporated the ability to run secure Java applets within web pages. Java quickly became popular. With the advent of Java 2, new versions had multiple configurations built for different types of platforms. For example, J2EE was for enterprise applications and the greatly stripped down version J2ME was for mobile applications. J2SE was the designation for the Standard Edition. In 2006, for marketing purposes, new J2 versions were renamed Java EE, Java ME, and Java SE, respectively.

In 1997, Sun Microsystems approached the ISO/IEC JTC1 standards body and later the Ecma International to formalize Java, but it soon withdrew from the process. Java remains a de facto standard that is controlled through the Java Community Process. At one time, Sun made most of its Java implementations available without charge although they were proprietary software. Sun's revenue from Java was generated by the selling of licenses for specialized products such as the Java Enterprise System. Sun distinguishes between its Software Development Kit (SDK) and Runtime Environment (JRE) which is a subset of the SDK, the primary distinction being that in the JRE, the compiler, utility programs, and many necessary header files are not present.

On 13 November 2006, Sun released much of Java as free software under the terms of the GNU General Public License (GPL). On 8 May 2007 Sun finished the process, making all of Java's core code open source, aside from a small portion of code to which Sun did not hold the copyright.

JAVA IDE

Java IDE makes us easier to make a program because we don’t need to remember the syntax and we can compile just with one click. For Java Programming Language, I suggest you to use NetBeans 6.0 and install Java Development Kit (1.6) which are free licensed. JCreator also can be used, but you must purchase a licensed. So, I suggest to use NetBeans 6.0 for learning.

You can download it here :
http://java.sun.com/javase/downloads/index.jsp


Source : en.wikipedia.org/wiki


[ Read More ]


[WISE WORD] A Story About Frog

Friday, February 22, 2008

A Story About FROG

One day there was a competition. That was a race competition and the participants were frogs. The first frog who can climb and reach the top of the tower would be the winner. Then the competition was begun. Frogs were trying hard to climb that tower, many audiences screamed "It's impossible to reach the top of the tower because it's too high". What have the audiences said became true, many frogs were falling down. Finally just one frog left, and that frog can reach the top. He was a winner. He was succeeded lose his frightened. The audiences were confused why it could be happened. In fact the frog who was the winner was deaf so he couldn't hear what the audiences have screamed.


WHAT YOU THINK IT'S BECOME TRUE SO ALWAYS POSITIVE THINKING and WHAT YOU HEAR IS INFLUENTED YOUR MIND N POWER SO BECOME A "DEAF" IS THE BEST WAY, NEVER HEAR WORDS THAT IS NEGATIVE. BECAUSE THE NEGATIVE WORD CAN DROP OUR WISHED N OUR EFFORT...ALWAYS BELIEVES YOURSELF N NEVER SAY NEVER N IMPOSSIBLE!

[ Read More ]


[C Programming Language] Repetition/Looping in C Programming Language

Saturday, February 16, 2008

REPETITION / LOOPING IN C PROGRAMMING LANGUAGE

Repetiton / Looping :

- A process which is done contionusly until particular value. If the limit isn’t typed, then syntax will be error because that process will be an infinite loop.

Looping which is usually used is Counting Loops. Why is it called conting loops? Because its repetition is managed by a loop control variable whose value represents a count. It is used when we can determine how many loops will be needed exactly.

The pseudocode of Counting Loops :

Set loop control variable to an initial value of 0

While loop control variable <>

... //Do something multiple times

Increase loop control variable by 1.

Three types of Counting Loops in C Programming Language :

a. FOR

Syntax :

for(initialize; test; update)

{

//Steps to perform each iteration

}

Initialize - - > initial condition of control variable

Test - - > relational expression which is a condition

Update - - > change the value of control variable

For Example :

int p = 0;

int i;

for (i=0;i<10;i++)

{

p=p+i;

}

Note :

p = p + 1 is equal with p++ and p += 1.

Flowchart :

b. WHILE (Pre Tested Loop) :

Syntax :

While(condition)

{

//Steps to perform. These should eventually

// result in condition being false

}

For Example :

int p=0;

int i=0; //initialization

while (i<10) //testing

{

p=p+i;

i++; //updating

}

Note :

If any of initialization, testing and updating are skipped, it may produce an infinite loop.

Flowchart :

c. DO-WHILE (Post Tested Loop) :

Syntax :

Do

{

//Steps to perform. These should eventually

// result in condition being false

}

While (condition);

For Example :

int i=0 //initialization

int p=0;

do

{

p=p+1;

i++; //updating

}

while (i<10); //testing

Flowchart :

Debug and Test Looping Programs :

1. Using debugger programs.

2. Use several printf statement to output the value of variables.

3. Testing the programs with try and error.

[ Read More ]


[C Programming Language] Standard Function in C Programming Language

C Programming Language Standard Function

Functions which is often used in C Programming Language :

a. printf

a function in stdio.h library which is used to show string and also placeholders to screen.

b. puts

a function used to show a string to screen when the placeholders isn’t used.

c. scanf

a function which is used to store data whose type is represented by a placeholder in string format to variable memory address which has been decided.

d. getch

a function which is used to read data whose type is character without key ENTER pressed and it won’t be showed. This function is usually used to show output on the screen until key ENTER pressed.

e. getche

a function which is used to read data whose type is character without key ENTER pressed and the character will be showed on the screen.

f. getchar

a function which is used to read data whose type is character, the character will be showed on screen and must be finished with key ENTER pressed.

g. clrscr

a function which is used to clear screen and move the cursor back to the upper left corner.

h. %3d dan %-3d

int x=1;

%3d will show : _ _ 1 - - > it still give 2 space

%-3d will show : 1 - - > empty space will be deleted.



Function Random and Randomize in Dev C++ :

1. Randomize :

To make randomize in order to produce a different random number every time the program running.

Syntax : srand ((unsigned)time(NULL));

2. Random(int num) :

To get a random number between 0 – (num – 1).

Syntax : int x = rand( )% (int num);

For example :

#include

#include

#include //definition of srand, rand

#include //definition of time

int main

{

int n,

x;

printf(“Enter the value of maximum random number : “);

scanf(“%d”,&n);

srand((unsigned)time(NULL));

x = rand()%100;

printf(“Random Number : %d\n”,x);

getch();

}

[ Read More ]


[C Programming Language] C Programming Language Main Structure

C Programming Language Main Structures

C Programming Language Elements :

1. Preprocessor directives

Command line which is given instruction to preprocessor.

There are two types of preprocessor : #include and #define.

#include library.h tell preprocessor the library to find the meaning of standard identifier.

#define NAME value tell preprocessor to change every identifier NAME with value before the program was compiled.

Example :

#include stdio.h

#define PI 3.14

2. Comment

Texts which is started with /* or // and finished with */, and contains information about program in order to make the program is understood easily by other programmer. Compiler will ignore comments.

3. Main Function

Syntax :

int main(void)

{

/* main function */

}

Main function is made up from 2 parts :

1. Declaration

2. Executeable Statement

4. Reserved Word and Identifier

Reserved Word :

- word which has special meaning in C and can’t be used again for other.

Example : int, void, double, return, etc.

Identifier :

a. Standard Identifier :

A word which has special meaning in C but it can’t be redefined by user(not recommended).

Example : printf, scanf, etc.

b. User Defined Identifier :

A word which is choosed by user to rename memory cell and user defined operation.

Example : miles, name, x, PI, etc


Expression Evaluation Rule :

1. Parentheses Rule

2. Operator Presedence Rule

From High to Low :

Function calls

!, +, -, & (operator unary)

*, /, %

+, -

<, <=, >=, >

==, !=

&&

||

=

3. Associative Rule

Unary - - > evaluate from Right to Left

Binary - - > evaluate from Left to Right



[ Read More ]


[C Programming Language] Branching (IF ELSE / SWITCH CASE) in C Programming Language

Friday, February 15, 2008

BRANCHING/ DECISION
(IF ELSE / SWITCH CASE)



Three Main Construction of Programming :

1. Sequential

2. Branching / Decision

3. Looping / Repetition

Branching :

- A process to make a decision based on the condition which has been evaluated before.

There are two types of branching :

1. IF – ELSE

Syntax : if (condition){

statement – 1;

statement – n;

}

else if (condition){

statement – 1;

statement – n;

}

Flowchart :

Example :

#include

#include

int main()

{

int T;

printf("Enter temperature (Celcius) : ");

scanf("%d",&T);

if (T>30)

{

printf("Arghhhhhhh, Hot!");

}

else if (T<0)

{

printf("Ouchhhhh, Cold !");

}

else printf("Yummy! Cool.");

getch();

return(0);

}

2. SWITCH – CASE

Syntax : switch (kondisi) {

case 1 : pernyataan-1;

break;

case 2 : pernyataan-2;

break;

.....

.....

case n : pernyataan-n;

break;

default : pernyataan-m

}

Flowchart :

Example :

#include

#include

int main()

{

char IP;

printf("Enter your result in alphabet : ");

scanf("%c",&IP);

switch (IP)

{

case 'A' : printf("4");

break;

case 'B' : printf("3");

break;

case 'C' : printf("2");

break;

case 'D' : printf("1");

break;

case 'E' : printf("0");

break;

default : printf("The input isn’t valid.");

}

getch();

return(0);

}

The difference between IF-ELSE and SWITCH-CASE :

IF ELSE :

To make a decision between 2 choices. For example :

If the value is greater than 70 (seventy) then the student passes the exam.

Else, the student doesn’t pass the exam.

SWITCH CASE :

To make a decision which has more than 2 choices. For example :

A is converted to 4.

B is converted to 3.

C is converted to 2.

D is converted to 1.

E is converted to 0.

[ Read More ]