Wednesday, April 9, 2014
Tuesday, March 25, 2014
Coldfusion_8_Training
ColdFusion Training Overview
This ColdFusion 8 course teaches attendees how to build their first data-driven web applications using ColdFusion.
ColdFusion Training Prerequisites :
To gain the most from the class, you should already have:
- A familiarity with Web terminology
- An understanding of Web server characteristics
- Experience with the HTML tag set and syntax
- Familiarity with the SQL command set, including SELECT, INSERT, UPDATE, and DELETE
- Basic Adobe Dreamweaver Knowledge
Material will be upload on the 31 Mac 2014. Please come back later
Please download the material from this link :
1. Training tutorial files
Ebook related to Coldfusion 8 and Coldfusion MX
1. EBOOK_CF8__DEVELOPER_TUTORIAL
2. EBOOK_CFMX_COLDFUSION
3. EBOOK_CFMX_DEVELOPERS_COOKBOOK
4. EBOOK_CFMX_MASTERING_COLDFUSION
5. CF8INTRO TUTORIAL FILES
Wednesday, February 5, 2014
MAA TAKAFUL
MAA Takaful is a result of
a strategic joint venture between MAA Group Berhad (“MAAG”) – [Formerly known
as MAA Holdings Berhad] and Solidarity Company BSC (C) of Bahrain, one of the
leading companies in the Arab world.
On 21 February 2006, a
Joint Venture (JV) Agreement was signed with Solidarity, to form a JV company
called MAA Takaful to carry on the Takaful business.
On 3 March 2006, Bank
Negara Malaysia granted approval for a new Takaful licence for the joint
venture of MAAG and Solidarity. On 2 May 2006, MAA Takaful was incorporated
with a paid up capital of RM100 million and licensed on 1 July 2007 as a
composite Takaful Operator. Today, MAA Takaful has an agency force of over
10,000.
MAAG holds 75% equity
interest in MAA Takaful while Solidarity holds 25%.
MAA Takafulink is the FIRST Regular
Premium Investment Linked product to declare surplus sharing in 2009. And, yet
again we will declare a surplus sharing in 2010, 2011 and 2012.
Based on Lipper & CIMB Principal report.
All our 3 Takafulink Investment Linked funds (Growth, Balance & Income
Fund) were ranked No. 1 in 2010.
We are the FIRST Takaful Company that has
an Investment Linked "Flexi Fund".
We are the FIRST Takaful Company that offers
coverage for 46 Critical Illness.
While other takaful operators, generate losses in the
first 5 to 8 years of their operations. MAA Takaful is
the FIRST and only company, which has generated profits, from its
SECOND year of operations in 2009.
MAA Takaful is the FIRST company to not
only make a profit in the third year of operation in 2010. But, it is
the FIRST and only company to make profit with no carry forward
losses.
MAA Takaful is the FIRST Takaful company
in the World to have a comprehensive agency training program that is World
Standard - jointly develop with LIMRA USA andCERT.
Sunday, January 5, 2014
CSC570 EXAM ANSWER
This is the ANSWER for CSC570 that had been written by my senior.
a lot of thanks to them.
Semoga segala kebaikan yang diperolehi dari rujukan ini akan beroleh pahala dan keberkatan dariNya.
CSC570 2010 JAN
CSC570 2010 APRIL
a lot of thanks to them.
Semoga segala kebaikan yang diperolehi dari rujukan ini akan beroleh pahala dan keberkatan dariNya.
CSC570 2010 JAN
CSC570 2010 APRIL
Friday, December 13, 2013
Jawapan Jurutera Kepada Para Pengkritik Kereta Nasional
APABILA Proton mengumumkan model terbaru Perdana, ramai yang respon dengan negatif terhadap rupa bentuk model tersebut yang mirip Honda Accord. Seperti biasa, cemuhan demi cemuhan dilemparkan kepada Proton di atas pengeluaran model ini.
Saya suka untuk memberi pandangan berdasarkan beberapa fakta berikut:
1- Saya kurang senang mendengar kritikan serta cemuhan terhadap Proton ini, tatkala pada masa yang sama apabila Kia mengeluarkan model seakan Audi, ramai yang memuji, juga tatkala Honda mengeluarkan model Accord 2011 yang seakan Audi, ramai juga yang memuji dan membelinya. Bahkan Mazda 6 tahun 2013 juga mirip Lexus, tiada pula yang mencemuh. Mentaliti sebegini wujud sifat dualisma, di mana berlakunya tindakan pilih kasih dalam kritikan.
2- Proton Suprima S adalah satu contoh model yang direka sendiri. Tidak meniru hasil orang lain. Namun bagaimanakah prestasi jualannya? Tidak memberangsangkan. Pengkritik tetap membandingkan Proton dengan Honda, Kia Rio dan seumpamanya. Tapi apabila model yang dikeluarkan mirip Honda, mereka mengutuk pula. Perkara ini saya membuatkan saya tidak faham.
3- Ramai pengkritik tidak memahami hakikat industri automotif yang ‘super-kompetetif’. Kilang Mitsubishi di Australia pada tahun 2006 pernah ditutup selama empat minggu kerana tiada permintaan. Majikan lama saya, Ford Australia di Geelong baru-baru ini telah mengisytiharkan mereka akan menutup kilang mereka mulai tahun 2016 kerana mengalami kerugian yang cukup besar, di mana mereka telah mengumpul kerugian sebanyak AUD$600 juta sejak 5 tahun kebelakangan ini. Ford telah bertapak di Australia selama 90 tahun, jadi bagaimanakah pula agaknya Proton yang hanya 1/3 usia berbanding Ford Australia berdepan dengan cabaran ini?
4- “Rebadging” atau penjenamaan semula bukanlah sesuatu yang aib dalam industri automotif. Pengeluar kereta terbesar dunia, General Motors (GM), telah melakukan strategi ini terhadap puluhan model kenderaan mereka. Cuba bandingkan Chevrolet Tahoe dengan Cadillac Escalade, dan Chevrolet Lumina dengan Holden Redline, kita akan nampak jelas bahawa perbezaannya hanya pada lambang jenama dan hiasan dalaman. Benar, jenama-jenama ini di bawah satu syarikat yang sama iaitu GM, namun dari sudut strategi, tidak ada bezanya antara kedua ini. Bahkan kritikan yang sama tidak pula diberikan kepada Perodua di atas strategi mereka “rebadging” model Myvi dan Daihatsu/Toyota, hanya kerana mereka ada kerjasama rasmi dengan Toyota. Model Perdana yang baru ada kerjasama dengan Honda bahkan Saga yang pertama dahulu pun ada kerjasama dengan Mitsubishi. Kritikan yang “pilih kasih” menyebabkan Proton menjadi ibarat “punching bag”. Buat apa pun dikira salah.
5- Mungkin yang terbaik ialah tutup sahaja Proton, agar tidak ada lagi “punching bag” tempat melepas geram dan kemarahan. Mungkin yang terbaik ialah rakyat Malaysia hidup seperti negara Timur Tengah yang hanya menjadi pelanggan kepada jenama-jenama kereta terbaik dunia. Tak payah susah-susah buat kereta sendiri. Namun saya rasa seandainya Proton ditutup, akan wujud laungan kemarahan yang baru iaitu “Mengapa Malaysia tidak ada kereta sendiri?”
Akhir kata, saya mengharapkan satu perubahan dalam mentaliti sesetengah rakyat Malaysia. Buat pengetahuan semua, saya sendiri tidak pernah membeli Proton, tetapi saya mengambil sikap berpada-pada dalam kritikan dengan mengetahui besarnya cabaran syarikat kecil Proton dalam persaingan industri automotif dunia. Dengan cabaran masa kini, Proton tak “bungkus” pun dah kira mujur.
Ya betul, jika anda tidak menyukai Proton atau merasakan Proton tidak sesuai dengan gaya hidup anda, tak perlulah membelinya. Tindakan anda tidak membeli Proton telah pun memberi mesej jelas “Saya tak suka Proton”.
Namun, yang saya kecewa ialah sikap sesetengah insan yang sudahlah tidak membeli Proton, malah melemparkan cemuhan dan kebencian yang amat kepada Proton, sehinggakan orang yang asalnya ingin membeli Proton pun tak jadi membelinya. Ini ibarat mencurah cuka ke dalam luka.
Engr. Hj Norzafry B Norhalim Mantan Presiden Pembina.
Sumber: Tengoktvonline.
I Support National Car!
XML Schemas
XML
Schemas are much more powerful than DTDs.
XML Schemas Support Data
Types
One
of the greatest strength of XML Schemas is the support for data types.
With
support for data types:
- It
is easier to describe allowable document content
- It
is easier to validate the correctness of data
- It
is easier to work with data from a database
- It
is easier to define data facets (restrictions on data)
- It
is easier to define data patterns (data formats)
- It
is easier to convert data between different data types
XML Schemas use XML
Syntax
Another
great strength about XML Schemas is that they are written in XML.
Some
benefits of that XML Schemas are written in XML:
- You
don't have to learn a new language
- You
can use your XML editor to edit your Schema files
- You
can use your XML parser to parse your Schema files
- You
can manipulate your Schema with the XML DOM
- You
can transform your Schema with XSLT
XML Schemas Secure Data
Communication
When
sending data from a sender to a receiver, it is essential that both parts have
the same "expectations" about the content.
With
XML Schemas, the sender can describe the data in a way that the receiver will
understand.
A
date like: "03-11-2004" will, in some countries, be interpreted as
3.November and in other countries as 11.March.
However,
an XML element with a data type like this:
<date
type="date">2004-03-11</date>
ensures
a mutual understanding of the content, because the XML data type
"date" requires the format "YYYY-MM-DD".
XML Schemas are
Extensible
XML
Schemas are extensible, because they are written in XML.
With
an extensible Schema definition you can:
- Reuse
your Schema in other Schemas
- Create
your own data types derived from the standard types
- Reference
multiple schemas in the same document
Well-Formed is not
Enough
A
well-formed XML document is a document that conforms to the XML syntax rules,
like:
- it
must begin with the XML declaration
- it
must have one unique root element
- start-tags
must have matching end-tags
- elements
are case sensitive
- all
elements must be closed
- all
elements must be properly nested
- all
attribute values must be quoted
- entities
must be used for special characters
Even
if documents are well-formed they can still contain errors, and those errors
can have serious consequences.
Think
of the following situation: you order 5 gross of laser printers, instead of 5
laser printers. With XML Schemas, most of these errors can be caught by your
validating software.
XML Schemas
XML
Schemas are much more powerful than DTDs.
XML Schemas Support Data
Types
One
of the greatest strength of XML Schemas is the support for data types.
With
support for data types:
- It
is easier to describe allowable document content
- It
is easier to validate the correctness of data
- It
is easier to work with data from a database
- It
is easier to define data facets (restrictions on data)
- It
is easier to define data patterns (data formats)
- It
is easier to convert data between different data types
XML Schemas use XML
Syntax
Another
great strength about XML Schemas is that they are written in XML.
Some
benefits of that XML Schemas are written in XML:
- You
don't have to learn a new language
- You
can use your XML editor to edit your Schema files
- You
can use your XML parser to parse your Schema files
- You
can manipulate your Schema with the XML DOM
- You
can transform your Schema with XSLT
XML Schemas Secure Data
Communication
When
sending data from a sender to a receiver, it is essential that both parts have
the same "expectations" about the content.
With
XML Schemas, the sender can describe the data in a way that the receiver will
understand.
A
date like: "03-11-2004" will, in some countries, be interpreted as
3.November and in other countries as 11.March.
However,
an XML element with a data type like this:
<date
type="date">2004-03-11</date>
ensures
a mutual understanding of the content, because the XML data type
"date" requires the format "YYYY-MM-DD".
XML Schemas are
Extensible
XML
Schemas are extensible, because they are written in XML.
With
an extensible Schema definition you can:
- Reuse
your Schema in other Schemas
- Create
your own data types derived from the standard types
- Reference
multiple schemas in the same document
Well-Formed is not
Enough
A
well-formed XML document is a document that conforms to the XML syntax rules,
like:
- it
must begin with the XML declaration
- it
must have one unique root element
- start-tags
must have matching end-tags
- elements
are case sensitive
- all
elements must be closed
- all
elements must be properly nested
- all
attribute values must be quoted
- entities
must be used for special characters
Even
if documents are well-formed they can still contain errors, and those errors
can have serious consequences.
Think
of the following situation: you order 5 gross of laser printers, instead of 5
laser printers. With XML Schemas, most of these errors can be caught by your
validating software.
XML
documents can have a reference to a DTD or to an XML Schema.
A Simple XML Document
Look
at this simple XML document called "note.xml":
<?xml
version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A DTD File
The
following example is a DTD file called "note.dtd" that defines the
elements of the XML document above ("note.xml"):
<!ELEMENT note
(to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
The
first line defines the note element to have four child elements: "to,
from, heading, body".
Line
2-5 defines the to, from, heading, body elements to be of type
"#PCDATA".
An XML Schema
The
following example is an XML Schema file called "note.xsd" that
defines the elements of the XML document above ("note.xml"):
<?xml
version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The
note element is a complex type because it contains other elements.
The other elements (to, from, heading, body) are simple types because they do not contain other
elements. You will learn more about simple and complex types in the following
chapters.
A Reference to a DTD
This
XML document has a reference to a DTD:
<?xml
version="1.0"?>
<!DOCTYPE note SYSTEM
"http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<!DOCTYPE note SYSTEM
"http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A Reference to an XML
Schema
This
XML document has a reference to an XML Schema:
<?xml
version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML Schemas
XML
Schemas are much more powerful than DTDs.
XML Schemas Support Data
Types
One
of the greatest strength of XML Schemas is the support for data types.
With
support for data types:
- It
is easier to describe allowable document content
- It
is easier to validate the correctness of data
- It
is easier to work with data from a database
- It
is easier to define data facets (restrictions on data)
- It
is easier to define data patterns (data formats)
- It
is easier to convert data between different data types
XML Schemas use XML
Syntax
Another
great strength about XML Schemas is that they are written in XML.
Some
benefits of that XML Schemas are written in XML:
- You
don't have to learn a new language
- You
can use your XML editor to edit your Schema files
- You
can use your XML parser to parse your Schema files
- You
can manipulate your Schema with the XML DOM
- You
can transform your Schema with XSLT
XML Schemas Secure Data
Communication
When
sending data from a sender to a receiver, it is essential that both parts have
the same "expectations" about the content.
With
XML Schemas, the sender can describe the data in a way that the receiver will
understand.
A
date like: "03-11-2004" will, in some countries, be interpreted as
3.November and in other countries as 11.March.
However,
an XML element with a data type like this:
<date
type="date">2004-03-11</date>
ensures
a mutual understanding of the content, because the XML data type
"date" requires the format "YYYY-MM-DD".
XML Schemas are
Extensible
XML
Schemas are extensible, because they are written in XML.
With
an extensible Schema definition you can:
- Reuse
your Schema in other Schemas
- Create
your own data types derived from the standard types
- Reference
multiple schemas in the same document
Well-Formed is not
Enough
A
well-formed XML document is a document that conforms to the XML syntax rules,
like:
- it
must begin with the XML declaration
- it
must have one unique root element
- start-tags
must have matching end-tags
- elements
are case sensitive
- all
elements must be closed
- all
elements must be properly nested
- all
attribute values must be quoted
- entities
must be used for special characters
Even
if documents are well-formed they can still contain errors, and those errors
can have serious consequences.
Think
of the following situation: you order 5 gross of laser printers, instead of 5
laser printers. With XML Schemas, most of these errors can be caught by your
validating software.
XML
documents can have a reference to a DTD or to an XML Schema.
A Simple XML Document
Look
at this simple XML document called "note.xml":
<?xml
version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A DTD File
The
following example is a DTD file called "note.dtd" that defines the
elements of the XML document above ("note.xml"):
<!ELEMENT note
(to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
The
first line defines the note element to have four child elements: "to,
from, heading, body".
Line
2-5 defines the to, from, heading, body elements to be of type
"#PCDATA".
An XML Schema
The
following example is an XML Schema file called "note.xsd" that
defines the elements of the XML document above ("note.xml"):
<?xml
version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The
note element is a complex type because it contains other elements.
The other elements (to, from, heading, body) are simple types because they do not contain other
elements. You will learn more about simple and complex types in the following
chapters.
A Reference to a DTD
This
XML document has a reference to a DTD:
<?xml
version="1.0"?>
<!DOCTYPE note SYSTEM
"http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<!DOCTYPE note SYSTEM
"http://www.w3schools.com/dtd/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A Reference to an XML
Schema
This
XML document has a reference to an XML Schema:
<?xml
version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Thursday, December 12, 2013
6 TYPE OF SORTING
Notes
sorting
1. Bubble
sort
public
static void BubbleSort( int arr[] ) {
int n = arr.length;
for ( int i=0; i <= ( n - 2 ); i++)
for ( int j=0; j <= ( n - 2 - i );
j++)
if (arr[j+1] < arr[j])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
2. Selection
sort
The
selection sort improves on the bubble sort by making only one exchange for
every pass through the list. In order to do this, a selection sort looks for
the largest value as it makes a pass and, after completing the pass, places it
in the proper location. As with a bubble sort, after the first pass, the
largest item is in the correct place. After the second pass, the next largest
is in place. This process continues and requires n−1 passes to sort n items,
since the final item must be in place after the (n−1) st pass.
public
static void SelectionSort( int
arr[] ) {
int n = arr.length;
for ( int i=0; i <= ( n - 2 ); i++)
for ( int j=0; j <= ( n - 2 - i );
j++)
if (arr[j+1] < arr[j])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
int
unsortedArray[] = {17,3,10,16,12,4,27,15,30,1,8,3
int i;
System.out.println("Before Sorting
SelectionSort :");
for(i=0; i<unsortedArray.length; i++)
{
System.out.print(unsortedArray[i] +
" ");
}
SelectionSort(unsortedArray); //Pass the
array to be sorted and its length.
3. The
Insertion Sort
The insertion sort, although still O(n2), works in a
slightly different way. It always maintains a sorted sublist in the lower
positions of the list. Each new item is then “inserted” back into the previous
sublist such that the sorted sublist is one item larger. Figure 4 shows the
insertion sorting process. The shaded items represent the ordered sublists as
the algorithm makes each pass.
public static void
InsertionSort( int arr[] ) {
int n =
arr.length;
int
v,j;
for (
int i=1; i <= ( n - 1 ); i++)
{
v
= arr[i];
j
= i - 1;
while( j>= 0 && arr[j]
> v )
{
arr[j+1] = arr[j];
j = j - 1;
}
arr[j+1] = v;
}
}
4. The
Merge Sort
We now turn our attention to using a divide and
conquer strategy as a way to improve the performance of sorting algorithms. The
first algorithm we will study is the merge sort. Merge sort is a recursive
algorithm that continually splits a list in half. If the list is empty or has
one item, it is sorted by definition (the base case). If the list has more than
one item, we split the list and recursively invoke a merge sort on both halves.
Once the two halves are sorted, the fundamental operation, called a merge, is
performed. Merging is the process of taking two smaller sorted lists and
combining them together into a single, sorted, new list.
Merge Sort Recursive
import java.io.*;
import java.util.*;
import java.lang.*;
class MergeSort {
static
public void DoMerge(int [] numbers, int left, int mid, int right)
{
int []
temp = new int[25];
int i,
left_end, num_elements, tmp_pos;
left_end = (mid - 1);
tmp_pos = left;
num_elements = (right - left + 1);
while
((left <= left_end) && (mid <= right))
{
if
(numbers[left] <= numbers[mid])
temp[tmp_pos++] = numbers[left++];
else
temp[tmp_pos++] = numbers[mid++];
}
while
(left <= left_end)
temp[tmp_pos++] = numbers[left++];
while
(mid <= right)
temp[tmp_pos++] = numbers[mid++];
for (i
= 0; i < num_elements; i++)
{
numbers[right] = temp[right];
right--;
}
}
static
public void MergeSort_Recursive(int [] numbers, int left, int right)
{
int mid;
if
(right > left)
{
mid =
(right + left) / 2;
MergeSort_Recursive(numbers, left, mid);
MergeSort_Recursive(numbers, (mid + 1), right);
DoMerge(numbers, left, (mid+1), right);
}
}
public
static void main(String[] args)
{
int[]
numbers = { 3, 8, 7, 5, 2, 1, 9, 6, 4 };
int
len = 9;
System.out.println("MergeSort By Recursive Method");
MergeSort_Recursive(numbers, 0, len - 1);
for
(int i = 0; i < 9; i++)
System.out.println(numbers[i]);
}
}
Merge Sort Iterative
import java.io.*;
import java.util.*;
import java.lang.*;
class MergeSort {
static
public void DoMerge(int [] numbers, int left, int mid, int right)
{
int []
temp = new int[25];
int i,
left_end, num_elements, tmp_pos;
left_end = (mid - 1);
tmp_pos = left;
num_elements = (right - left + 1);
while
((left <= left_end) && (mid <= right))
{
if
(numbers[left] <= numbers[mid])
temp[tmp_pos++] = numbers[left++];
else
temp[tmp_pos++] = numbers[mid++];
}
while
(left <= left_end)
temp[tmp_pos++] = numbers[left++];
while
(mid <= right)
temp[tmp_pos++] = numbers[mid++];
for (i
= 0; i < num_elements; i++)
{
numbers[right] = temp[right];
right--;
}
}
static
public class MergePosInfo
{
public
int left;
public
int mid;
public
int right;
}
static
public void MergeSort_Iterative(int [] numbers, int left, int right)
{
int mid;
if
(right <= left)
return;
LinkedList<MergePosInfo> list1 = new
LinkedList<MergePosInfo>();
LinkedList<MergePosInfo> list2 = new
LinkedList<MergePosInfo>();
MergePosInfo info = new MergePosInfo();
info.left = left;
info.right = right;
info.mid = -1;
list1.add(info);
while(true)
{
if(list1.size() == 0)
break;
left = list1.get(0).left;
right = list1.get(0).right;
list1.remove(0);
mid = (right + left) / 2;
if(left < right)
{
MergePosInfo info2 = new MergePosInfo();
info2.left = left;
info2.right = right;
info2.mid = mid + 1;
list2.add(info2);
info.left = left;
info.right = mid;
list1.add(info);
info.left = mid + 1;
info.right = right;
list1.add(info);
}
}
for
(int i = 0; i < list2.size(); i++)
{
DoMerge(numbers, list2.get(i).left, list2.get(i).mid,
list2.get(i).right);
}
}
public
static void main(String[] args)
{
int[]
numbers = { 3, 8, 7, 5, 2, 1, 9, 6, 4 };
int
len = 9;
System.out.println();
System.out.println("MergeSort
By Iterative Method");
MergeSort_Iterative(numbers, 0, len - 1);
for
(int i = 0; i < 9; i++)
System.out.println(numbers[i]);
}
}
HEAP SORT :
//Source
code for Heap Sort
public class HeapSort
{
private static int[] a;
private static int n;
private static int left;
private static int right;
private static int largest;
public static void buildheap(int []a){
n=a.length-1;
for(int i=n/2;i>=0;i–){
maxheap(a,i);
}
}
public static void maxheap(int[] a, int i){
left=2*i;
right=2*i+1;
if(left <= n && a[left] > a[i]){
largest=left;
}
else{
largest=i;
}
if(right <= n && a[right] > a[largest]){
largest=right;
}
if(largest!=i){
exchange(i,largest);
maxheap(a, largest);
}
}
public static void exchange(int i, int j){
int t=a[i];
a[i]=a[j];
a[j]=t;
}
public static void sort(int []a0){
a=a0;
buildheap(a);
for(int i=n;i>0;i–){
exchange(0, i);
n=n-1;
maxheap(a, 0);
}
}
public static void main(String[] args) {
int []a1={4,1,3,2,16,9,10,14,8,7};
sort(a1);
for(int i=0;i<a1.length;i++){
System.out.print(a1[i] + " ");
}
}
}
public class HeapSort
{
private static int[] a;
private static int n;
private static int left;
private static int right;
private static int largest;
public static void buildheap(int []a){
n=a.length-1;
for(int i=n/2;i>=0;i–){
maxheap(a,i);
}
}
public static void maxheap(int[] a, int i){
left=2*i;
right=2*i+1;
if(left <= n && a[left] > a[i]){
largest=left;
}
else{
largest=i;
}
if(right <= n && a[right] > a[largest]){
largest=right;
}
if(largest!=i){
exchange(i,largest);
maxheap(a, largest);
}
}
public static void exchange(int i, int j){
int t=a[i];
a[i]=a[j];
a[j]=t;
}
public static void sort(int []a0){
a=a0;
buildheap(a);
for(int i=n;i>0;i–){
exchange(0, i);
n=n-1;
maxheap(a, 0);
}
}
public static void main(String[] args) {
int []a1={4,1,3,2,16,9,10,14,8,7};
sort(a1);
for(int i=0;i<a1.length;i++){
System.out.print(a1[i] + " ");
}
}
}
The Quick Sort
The quick sort uses divide and conquer to gain the
same advantages as the merge sort, while not using additional storage. As a
trade-off, however, it is possible that the list may not be divided in half.
When this happens, we will see that performance is diminished.
A quick sort first selects a value, which is called
the pivot value. Although there are many different ways to choose the pivot
value, we will simply use the first item in the list. The role of the pivot
value is to assist with splitting the list. The actual position where the pivot
value belongs in the final sorted list, commonly called the split point, will
be used to divide the list for subsequent calls to the quick sort.
import java.io.*;
import java.util.*;
public class QuickSort
{
public
static void swap (int A[], int x, int y)
{
int temp
= A[x];
A[x] =
A[y];
A[y] =
temp;
}
//
Reorganizes the given list so all elements less than the first are
// before
it and all greater elements are after it.
public
static int partition(int A[], int f, int l)
{
int
pivot = A[f];
while (f
< l)
{
if
(A[f] == pivot || A[l] == pivot)
{
System.out.println("Only distinct integers allowed - C321");
System.out.println("students should
ignore this if statement");
System.out.exit(0);
}
while
(A[f] < pivot) f++;
while
(A[l] > pivot) l--;
swap
(A, f, l);
}
return
f;
}
public
static void Quicksort(int A[], int f, int l)
{
if (f
>= l) return;
int
pivot_index = partition(A, f, l);
Quicksort(A, f, pivot_index);
Quicksort(A, pivot_index+1, l);
}
public
static void main(String argv[])
{
int A[]
= new int[argv.length];
for (int
i=0 ; i < argv.length ; i++)
A[i]
= Integer.parseInt(argv[i]);
Quicksort(A, 0, argv.length-1);
for (int
i=0 ; i < argv.length ; i++) System.out.print(A[i] + " ");
System.out.println();
}}
Subscribe to:
Posts (Atom)