Tuesday, May 19, 2009

Watching JK-Wiranto on TV

I was back home late at night, it's about 8.30 after I change my clothes I had my dinner on living room, accompanied by my living friends, we were watching tv together. I forgot the title of the show but the presenter was Helmy Yahya. Its on Trans7. The show already run, it's not live show. The setting is in studio with hundreds of audience there, most of them wearing golden yellow dress, the golkar color. I guess it's the same place with Bukan Empat Mata place with Tukul Arwana as the star.

There are four guests who give questions in front of JK-Wiranto, Oppie Andariesta, a woman that I forgot the name, Todung Mulya Lubis, and Kak Seto. I was late not watching the show from beginning. In the middle of the show there is a video about BLT in Kediri which killed some poeple to get 30000 rupiah because of the crowded to get the money. Oh dear what's our fault until there's happened in Kediri. I cannot imagine it happened in a wealth city such Kediri. I forgot the question from the woman, she asked about real implementation from the candidate for solving the wealthiness of the people. Wiranto is great speaker, I forgot what exactly he said, but I think that he said that it's a casuistic thing that should not be generalize it, many people helped because of BLT. I forgot the detail of the answer but I remember when Helmy Yahya adding the question: "Is BLT will happened again in the future?". JK said that BLT is not an anual program, it's ad-hoc program. The idea of BLT rise in his room in the past years because we need a way to help poor people if the gasoline price is rise. So BLT happened only twice when the gasoline price is up. In the 2004 (perhaps, I forget again) and 2008. That tragedy is happen in March 2009 because BLT gives money for ten months. And it will never happen again in the future.

And then Oppie asked about women labour in foreign country. I think both JK-Wiranto answer it with a diplomatic way that they want to have working field in Indonesia and the labour should working here. And then Helmy add the question that there were women as a carrier of drugs. JK said that women as the carrier of drug is because it minimalize the oportunity known by the police rather than Men as the carrier. It's not the problem of the women as the carrier, the problem is the drug. And then Oppie asked again about the women rights. And Wiranto answered it that actually in Indonesia the women rights is already has much attention, there already quota in somewhere some occasion for women, and that only happend in this country.

Kak Seto question is about children and education, he asked about Ujian Nasional. JK said that at the past time he met people from neighbour country, Malaysia, Singapore, or Philipines. That those country have a harder exam and higher passing grade for graduation. So the first time UN grade limit is 3.5 and the next year it will higher be 4, and so on. It just because we didn't want to be behind from those countries. And it's not same passing grade for each region, perhaps it's 8 in Jakarta and 3 in east Indonesia. And he add that we should happy because of the afraid of fail in UN, because there were Istighosah, praying for passing, and minimize the students war between schools. And Kak Seto asked again about the recipe to have a great and harmony family. Wiranto said that his recipe is by giving his family kind of freedom and he role as a good man in actual life.

And then Todung asked about how to take money back from out of the country, in case the money may a hard or wrong money because of the processing the natural recource we have. And both JK-Wiranto answer it with a diplomatic way. AFAIR JK already ask the ministry for the rules, and he said that in case of the resource is mainly is mining, so to optimize the result we should use it for ourselves by adding the using industry or some like that.

And then Helmy asked both JK-Wiranto ask their family enter the stage, JK wife's named Mufida, they brought four children in that stage, three girls and a boy, and ten of grand children, two of them are in the stage. While JK mention their names, one of his children angry because he wrong to mention his name, JK mention his call name not the actual name. While Wiranto wife's name is ended with Usman, he said that means she is the daughter of mr. Usman. She is from Gorontalo same island with JK, he said that his children is Jago (Java-Gorontalo). They have two doughters Maya and Lia, and a son. Maya and his brother is in America while Lia is in Jakarta but did not come to the show, but there's Lia's husband and their three of four children. All of their family is religious family, very happy to see that.

Im sorry that I cannot remember the details of the show, and honestly Im not good in writing or talking politics. It's a hard thing for me. But both JK and Wiranto are smart people, they able to speak without script, they communicate friendly without trying to be grace, they were not like a student who read report in front of foreign people saying that Indonesia had great progress in economy and democracy.

Saturday, May 16, 2009

The Prayer

Call me the prayer, Perhaps I don't know well of my religion knowledge, but no matter what I do just please categorized me as the prayer.

Perhaps I'm not a good person, and I knew Im not, Im a bad person in society, a selfish and a hedonist person, I don't know and not too enthusiastic with what happened to my neighbors or my friends. I'm the villain in the movie, Im the joker in the Dark Night, or perhaps the two face. But is it wrong for me to take this path? as a religious person, as a good wannabe person.

It is a shame for me as a person that born in religious environment but don't know much about my religion, Everybody around my neighborhood in surabaya is great alquran reader, some of them able to read arabic with no harokat, they remember a lot of praying reading and the how to's. While me.. Im nothing in my religious view.

But that's me, it's already happened to my life, there are so many regret in this life and I don't want to be in that regret forever. Just receive me as the way I am, with the all that I have.

I fix my life pieces by pieces, I rebuild my career again, and thanks god I've been in this office and feel received with all the aspect of it. Today is exactly my a year plus two month in this office, it is the longest time for me for working, and I hope it will happen to me for long time, for longer years forward. I was moving and moving again in my previous works, I don't want do that again, at least as far as this company need me, I will not search for other place.

Im a humble person, Im not expecting to be reach and success, I already used to live simple. Im a happy with the all that I have. I have great family that will always receive me when I back to Surabaya. I have a lot of friends, well it's not as much as you have I guess, but I have a lot of friends. And I have a great job, I build great application for users. I am an engineer, I dedicate may days for building software, I am an enthusiastic person to technology, Im a good learner.

I said to myself that working is praying, living is praying, Im not a holy person that clean of everything, and as an ordinary person I am a full of mistake, full of sin. It is far more easy for me to write it beautifully, I know it hard to do in real life, but I feel so in religious atmosphere right now, is it a mistake for me that I write what I want to do in my own life? I know I will far... far away for this ideal life, I just want to write it, perhaps I can read it again and useful for me or somebody else.

Queue and Stack With Linked List


This post is based on my senior post, his post is a C program about queue using Linked List, I made the java version and I extend it not only implementing queue with Linked List but also implementing stack.

I also improve my coding style, in which Im not write all of the stuff in main method, but I divide them into their own methods, so I have enqueue and dequeue method for queue, push and pop method for stack, also view and clear linked list method. So I only need call them in main method, it more clear and readable.

package stack.queue;

import java.util.Scanner;

class Node {
int info;
Node next;

public Node(int d) {
info = d;
}
}

public class LinkedListImpl {
static Node newNode;
static Node front;
static Node rear;
static Node tempNode;
static Scanner scanner = new Scanner(System.in);

public static void enqueue() {
System.out.print("Data enter: ");
newNode = new Node(scanner.nextInt());
if (front == null) {
front = newNode;
rear = newNode; //rear is never null, because if front is null,
//the new Node is also the rear
} else {
rear.next = newNode;
rear = newNode; //nothing happen with the front
}
System.out.println();
}
public static void dequeue() {
if (front != null) {
tempNode = front;
System.out.println("Data out = " + tempNode.info);
front = tempNode.next;
} else {
System.err.println("Queue is empty!");
}
System.out.println();
}
public static void push() { //push as front not as rear
System.out.print("Data enter: ");
newNode = new Node(scanner.nextInt());
if (front == null) {
front = newNode;
rear = newNode; //rear is never null, because if front is null,
//the new Node is also the rear
} else {
tempNode = front;
front = newNode;
front.next = tempNode; //nothing happen with the rear
}
System.out.println();
}
public static void pop() {
if (front != null) {
tempNode = front;
System.out.println("Data out = " + front.info);
front = tempNode.next;
} else {
System.err.println("Queue is empty!");
}
System.out.println();
}
public static void viewFromFront() {
tempNode = front;
while (tempNode != null) {
System.out.print(tempNode.info + " ");
tempNode = tempNode.next;
}
System.out.println("\n");
}
public static void clearList() {
front = null;
rear = null;
}
public static void main(String[] args) {
int choiceMain = 0;
do {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
System.out.println("Menu Implementation:");
System.out.println("1. QUEUE\t2. STACK\t3. EXIT FROM APPLICATION");
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
System.out.print("Please Choose Menu : ");
choiceMain = scanner.nextInt();
switch (choiceMain) {
case 1:
System.out.println("************************************************************");
System.out.println("Queue Menu:");
System.out.println("1. ENQUEUE\t2. DEDQUEUE\t3. VIEW\t4. EXIT FROM QUEUE");
System.out.println("************************************************************");
int choiceQueue = 0;
do {
System.out.print("Please Choose Menu : ");
choiceQueue = scanner.nextInt();
switch (choiceQueue) {
case 1: enqueue();
break;
case 2: dequeue();
break;
case 3: viewFromFront();
break;
case 4:
clearList();
System.err.println("Exiting From Queue...");
break;
}
} while (choiceQueue != 4);
break;
case 2:
System.out.println("************************************************************");
System.out.println("Stack Menu:");
System.out.println("1. PUSH\t2. POP\t3. VIEW\t4. EXIT FROM STACK");
System.out.println("************************************************************");
int choiceStack = 0;
do {
System.out.print("Please Choose Menu : ");
choiceStack = scanner.nextInt();
switch (choiceStack) {
case 1: push();
break;
case 2: pop();
break;
case 3: viewFromFront();
break;
case 4:
clearList();
System.err.println("Exiting From Stack...");
break;
}
} while (choiceStack != 4);
break;
case 3:
System.err.println("Exiting From Application...");
break;
}
} while (choiceMain != 3);
System.err.println("Application terminated.");
}
}

Thursday, May 14, 2009

Queue Using Stack


Tis post is the continues of my previous post and there will be two complete java program, the java version of my senior post and the revision version that I made in case in my opinion his program still have an error.

Queue as if in a line of waiting ticket for cinema has front and rear, the front is the the first person in that line who will get the ticket the first time, while the rear is the last person in that line that will get the ticket if he/she is lucky because he will get the ticket the last one.

If the first person already got his ticket, he will out from the line, and then the person behind him/her all person in the line move forward, I assume that got ticket person's named Imam, and the person behind him is Baihaqi, so Imam is no longer in the line, while Baihaqi is in the front now.

If we indexing the line by 0, 1, 2, 3, etc. Imam is no longer in the index, he already out for buying coke or chocolate milk for the movie, While Baihaqi is in index 0, before that he was in index 1. So do the last person named Ahmad, he is the rear or the last person in line, his index is decremented, from index number 30 now he is in index 29. And then there is a new person that also want to buy the ticket named Ali, now he is the rear or the last person in line, his index is 30, etc etc.

In queue there are enqueue and dequeue, enqueue is just like Ali when enter the line, he will be as the rear of the queue, his index is rear plus one, I mean in enqueue the rear is incremented while the front remains unchanged. While dequeue is just when Imam out from the line because of he already got the ticket, all the person moving forwards, now the person who is in the front now is change, the front person is Baihaqi not Imam anymore, but still the index of the front is always 0, and the rear is decremented.

In my senior program's there is a mistake about this, specifically in dequeue, I guess he thought that the front is the person, not the index, the first is Imam in front, and then after dequeue, Baihaqi is the front, but I think is a mistake, front and rear is refer to index, front is always 0, and rear is always change when enqueue or dequeue, if enqueue its increment, if dequeue its decrement.

I already capture the output of both program, and sign it when doing dequeue, after dequeueing it also print the index of the front and the rear, so it will more clear about them. Here is the full code of my senior program in java version:

package stack.queue;

import java.util.Scanner;

public class QueueUsingStack {
static final int MAXQUEUE = 5;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int[] queue = new int[MAXQUEUE];
int front = -1;
int rear = -1;
int choice;

do {
System.out.println("*******************************");
System.out.println("Menu:");
System.out.println("1. ENQUEUE\t2. DEDQUEUE\t3. VIEW\t4. EXIT");
System.out.println("*******************************");
System.out.print("Please Choose Menu : ");
choice = scanner.nextInt();
switch (choice) {
case 1://enqueue
if (rear < MAXQUEUE - 1) { //is queue not full yet?
System.out.print("Data enter = ");
queue[rear + 1] = scanner.nextInt();
rear++;
System.out.println();
if(rear == 0) front = 0;
} else {
System.err.println("Queue is Full");
}
break;
case 2: //dequeue
if (front <= rear) {//
System.out.println("Data out: " + queue[front]);
front++;

System.out.println("front: " + front + ", rear: " + rear);
} else {
System.err.println("Queue is Empty");
}
break;
case 3:
for (int i = front; i <= rear; i++) {
System.out.print(queue[i] + " ");
}
System.out.println();
break;
case 4:
System.out.println("Exit...");
}
} while (choice != 4);
System.err.println("Program terminated");
}
}


I mark bold for the front declaration and statements when dequeue, the front is a variable that can change, the first initial is -1 and it increment when dequeue, while in dequeue, it only increment the front, and the data of queue is not moving, all the remain data should move forwards.

Below is my program, the diferent is I made the front as constant, because it always 0, and while dequeue, all of the data is moving forwards, and the rear is decremented. And I also comment the checking if rear == 0 then front = 0, I make the font bold. About the initialization of rear as -1, is because I follow my senior, It only initialization, you can initialize rear as 0, or whatever the number is doesn't problem because it will checked inside the program.

package stack.queue;

import java.util.Scanner;

public class MyQueueUsingStack {
static final int MAXQUEUE = 5;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int[] queue = new int[5];
final int FRONT = 0;
int rear = -1;
int choice;

do {
System.out.println("*******************************");
System.out.println("Menu:");
System.out.println("1. ENQUEUE\t2. DEDQUEUE\t3. VIEW\t4. EXIT");
System.out.println("*******************************");
System.out.print("Please Choose Menu : ");
choice = scanner.nextInt();
switch (choice) {
case 1://enqueue
if (rear < MAXQUEUE - 1) { //is queue not full yet?
System.out.print("Data enter = ");
queue[rear + 1] = scanner.nextInt();
rear++;
System.out.println();
// if(rear == 0) front = 0;
} else {
System.err.println("Queue is Full");
}
break;
case 2: //dequeue
if (rear >= FRONT) {//is queue not empty yet?
System.out.println("Data out: " + queue[FRONT]);
//queue is moving
for (int i = FRONT; i < rear; i++) {
queue[i] = queue[i+1];
}
rear--;

System.out.println("front: " + FRONT + ", rear: " + rear);
} else {
System.err.println("Queue is Empty");
}
break;
case 3:
for (int i = FRONT; i <= rear; i++) {
System.out.print(queue[i] + " ");
}
System.out.println();
break;
case 4:
System.out.println("Exit...");
}
} while (choice != 4);
System.err.println("Program terminated");
}
}

Monday, May 11, 2009

Queue Using Double Linked List


This post is the continue of my previous post, and it is the java version of my senior post about queue using double link list, he use C, it implementing the data structure book by yedidyah langsam and andrew s. tanenbaum's book, a subject in bachelor of computer science.

In case in my senior post there is a comment that asked about double linked list, I want to describe about double linked list on my own word. it's a data structure which each object has three components:
- value, information that object had, it can be integer, or some other things, just like array of integer, or array of other things
- link to object in front of it. which is the same object type
- link to object in previous of it.

the head (the most front of list) did not have link to front object, and the rear did not have link to previous object, if both of those object have links, it called circular doubly linked list. fiuhhh feels like lecture when I write it, and I think I am a good lecture ^_^

By the way after I run the program which is the java version of my senior program, in case there's plenty example of double link list on net such as from java2s, I guess there still a question for my senior algorithm, I already capture the console of java version, and I think that program is not too queueing as properly.

Queue is just like when we want to buy ticket at the XII cinema, the first body in the head (front) will get his ticket first and then out from the list (FIFO). While stack is just like the order of oreo cake in a tuppleware, we put oreo one by one in one of thin tuppleware, and then we take out one by one also, the last oreo we put, the first one we take and eat with a glass of milk (LIFO).

When I run the program and then I insert the list in order like 10, 20, 30, and so on. The head (front) of the list it should be 10, the first one, not the last one, but when we choose to view the list, it say that 10 is the rear, and I think that the first mistake. The second mistake is when we choose Delete Front, It will delete the last input, I think it also a mistake, in the queue of XII ticketing, the Front is the first person in the line, so he/she is the first person will get the ticket, not the last one.

I will tell my senior about this mistake, and this is the full code of the program, just copy paste and run it in your environment as you want:

package stack.queue;

import java.util.Scanner;

class Node {
Node previous;
int info;
Node next;

public Node(int d) {
info = d;
}
}

public class QueueUsingDLL {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

Node newNode = null;
Node head = null;
Node tail = null;
Node tempNode = null;

int choice = 0;
do {
System.out.println("\n***************************************************************");
System.out.println("Menu:");
System.out.println("1. Insert Front\t2. View\t3. Search\t4. Delete Front\t5. Exit");
System.out.println("***************************************************************");
System.out.print("Please Choose Menu : ");
choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Data entry: ");
int data = scanner.nextInt();
System.out.println("You're entering " + data);
newNode = new Node(data);
if (head == null) {
head = newNode;
tail = newNode;
} else {
newNode.next = head;
head.previous = newNode;
head = newNode;
}
break;
case 2: // view
System.out.print("From HEAD: ");
tempNode = head;
while (tempNode != null) {
System.out.print(tempNode.info + " ");
tempNode = tempNode.next; // move to back
}
System.out.print("\nFrom TAIL: ");
tempNode = tail;
while (tempNode != null) {
System.out.print(tempNode.info + " ");
tempNode = tempNode.previous; // move to front
}
System.out.println("");
break;
case 3: // search
System.out.print("Searching number: ");
int search = scanner.nextInt();
tempNode = head;
while ((tempNode != null) && (tempNode.info != search)) {
tempNode = tempNode.next;
}
if ((tempNode != null) && (tempNode.info == search)) {
System.out.println("Data found");
} else {
System.err.println("Data not found");
}
break;
case 4: // delete front
// tempNode = head;
head = head.next;
if (head != null) {
head.previous = null;
System.out.println("Head deleted");
}
if (head == null)
tail = null;
break;
case 5:
System.err.println("Exit...\n");
break;
}
} while (choice != 5);
System.err.println("Program terminated");
}

}

Wednesday, May 6, 2009

Stack Using Array, Java Implementation of Langsam & Tanenbaum's Data Structure

I read my senior's post whom a lecturer in surabaya about stack using array, he is using C. I remember that problem arise in Data Structure when I was in bachelor, taken from Yedidyah Langsam and Andrew S. Tanenbaum's book. So I rewrite his code in java version. Feels great that you try to remembering what you learn for past years, and in fact at that time I donot understand at all about the subject.

package stack.queue;

import java.io.IOException;
import java.util.Scanner;

public class StackFromArray {
final static int MAX = 5;
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);

int stack[] = new int[MAX];
int top = -1;
int choice = 0;
do {
System.out.println("\n*******************************");
System.out.println("Menu:");
System.out.println("1. PUSH\t2. POP\t3. VIEW\t4. EXIT");
System.out.println("*******************************");
System.out.print("Please Choose Menu : ");
choice = scanner.nextInt();
switch (choice) {
case 1: //push
if (top >= MAX - 1)
System.err.println("Stack is full");
else {
System.out.print("Data You want to push : ");
int data = scanner.nextInt();
System.out.println("You pushed " + data);
stack[top + 1] = data;
top++;
}
break;
case 2: //pop
if (top < 0)
System.out.println("Stack is empty");
else {
System.out.print("Data out = " + stack[top]);
top--;
}
break;
case 3: //view
for (int i = 0; i < stack.length; i++)
System.out.print(stack[i] + " ");
System.out.println("\n");
break;
case 4: //view
System.out.println("Exit...\n");
break;
default:
break;
}
} while (choice != 4);
System.err.println("Program terminated");
}
}