Is there is an interface to deal with as XML file?
I made an application that depends on the data taken form an XML file, and
if the user want to update something in that application he have to change
the data contained in that xml file, but for sure i can't ask the user to
open the XML file and change it himself, so is there is a way or an
interface that can be used to edit this XML file or something that helps
me build that interface?
HINT: the changes that have to be made to the xml file to update the
application is a slight changes like adding or removing a node.
Busque
Sunday, 1 September 2013
Saturday, 31 August 2013
What is the number of comparisons using selection sort?
What is the number of comparisons using selection sort?
I have quick question about my program dealing with the number of
comparisons using selection sort. My program sorts an array of ints using
my selection sort class/method, display the sorted array, and it will
display the number of comparisons using my selection sort 2 class/method.
In my main/demo I have an array of 5 ints. It sorts them out fine but the
problem I am having is the number of comparisons. After I run it is says
it did 4 comparisons but shouldn't it be 10 instead? Due to the comparison
formula for selection being 1/2*n(n-1) or n(n-1)/2.
My selectionSort2 class/method is where my problem is. If you guys can
check out my selectionSort2 class/method that deals with the comparisons
and see what I am doing wrong I'll appreciate the help. It's the same as
my selectionSort class/method (which is right) but instead of sorting the
array, it just returns the amount of comparisons.
My demo:
ArrayInts[] myInts = new ArrayInts[5];
myInts[0] = new ArrayInts(3);
myInts[1] = new ArrayInts(9);
myInts[2] = new ArrayInts(6);
myInts[3] = new ArrayInts(1);
myInts[4] = new ArrayInts(2);
System.out.println("Unsorted array without using Selection Sort: ");
for(ArrayInts myInt:myInts){
System.out.println(myInt);
}
SelectionSort.selectionSort(myInts);
System.out.println(" ");
System.out.println("Sorted array using Selection Sort: ");
for(ArrayInts myInt:myInts){
System.out.println(myInt);
}
System.out.println(" ");
System.out.println("Number of comparisons using Selection Sort: " +
SelectionSort2.selectionSort2(myInts));
My selectionSort class/method that is used to only sort the array:
public class SelectionSort {
public static <T extends Comparable<? super T>> void selectionSort (T[]
data){
int min;
T temp;
for(int index=0; index < data.length-1; index++){
min = index;
for(int scan = index+1; scan < data.length; scan++)
if(data[scan].compareTo(data[min])<0)
min=scan;
temp = data[min];
data[min]=data[index];
data[index]=temp;
}
}
}
My ArrayInts class that is used to make the array:
public class ArrayInts implements Comparable<ArrayInts> {
public int num;
public ArrayInts(int initialNum) {
num = initialNum;
}
public String toString() {
return String.valueOf(num);
}
public int compareTo(ArrayInts other) {
int result;
if (num == other.num) {
result = 0;
} else if (num < other.num) {
result = -1;
} else {
result = 1;
}
return result;
}
}
My selectionSort2 class/method that is used to return the number of
comparisons:
public class SelectionSort2 {
public static <T extends Comparable<? super T>> int selectionSort2 (T[]
data){
int min;
T temp;
int comparisons=0;
for(int index=0; index < data.length-1; index++){
min = index;
for(int scan = index+1; scan < data.length; scan++)
if(data[scan].compareTo(data[min])<0)
min=scan;
temp = data[min];
data[min]=data[index];
data[index]=temp;
comparisons++;
}
return comparisons;
}
}
I have quick question about my program dealing with the number of
comparisons using selection sort. My program sorts an array of ints using
my selection sort class/method, display the sorted array, and it will
display the number of comparisons using my selection sort 2 class/method.
In my main/demo I have an array of 5 ints. It sorts them out fine but the
problem I am having is the number of comparisons. After I run it is says
it did 4 comparisons but shouldn't it be 10 instead? Due to the comparison
formula for selection being 1/2*n(n-1) or n(n-1)/2.
My selectionSort2 class/method is where my problem is. If you guys can
check out my selectionSort2 class/method that deals with the comparisons
and see what I am doing wrong I'll appreciate the help. It's the same as
my selectionSort class/method (which is right) but instead of sorting the
array, it just returns the amount of comparisons.
My demo:
ArrayInts[] myInts = new ArrayInts[5];
myInts[0] = new ArrayInts(3);
myInts[1] = new ArrayInts(9);
myInts[2] = new ArrayInts(6);
myInts[3] = new ArrayInts(1);
myInts[4] = new ArrayInts(2);
System.out.println("Unsorted array without using Selection Sort: ");
for(ArrayInts myInt:myInts){
System.out.println(myInt);
}
SelectionSort.selectionSort(myInts);
System.out.println(" ");
System.out.println("Sorted array using Selection Sort: ");
for(ArrayInts myInt:myInts){
System.out.println(myInt);
}
System.out.println(" ");
System.out.println("Number of comparisons using Selection Sort: " +
SelectionSort2.selectionSort2(myInts));
My selectionSort class/method that is used to only sort the array:
public class SelectionSort {
public static <T extends Comparable<? super T>> void selectionSort (T[]
data){
int min;
T temp;
for(int index=0; index < data.length-1; index++){
min = index;
for(int scan = index+1; scan < data.length; scan++)
if(data[scan].compareTo(data[min])<0)
min=scan;
temp = data[min];
data[min]=data[index];
data[index]=temp;
}
}
}
My ArrayInts class that is used to make the array:
public class ArrayInts implements Comparable<ArrayInts> {
public int num;
public ArrayInts(int initialNum) {
num = initialNum;
}
public String toString() {
return String.valueOf(num);
}
public int compareTo(ArrayInts other) {
int result;
if (num == other.num) {
result = 0;
} else if (num < other.num) {
result = -1;
} else {
result = 1;
}
return result;
}
}
My selectionSort2 class/method that is used to return the number of
comparisons:
public class SelectionSort2 {
public static <T extends Comparable<? super T>> int selectionSort2 (T[]
data){
int min;
T temp;
int comparisons=0;
for(int index=0; index < data.length-1; index++){
min = index;
for(int scan = index+1; scan < data.length; scan++)
if(data[scan].compareTo(data[min])<0)
min=scan;
temp = data[min];
data[min]=data[index];
data[index]=temp;
comparisons++;
}
return comparisons;
}
}
Multiple channel's message comes into single channel
Multiple channel's message comes into single channel
i am fresher of Spring Integration, i am confuing one question which i
have multiple channels but now i want to assemble messages from those
channel into single channel, how to implement it ? my senario is that i
have lots of businees modues and each module will corresponding to one
channel, those channels will receive the request then assemble the message
into one single channel , then output to the jms server:
is below code possible ?
<channel id='a'/> <bridge input-channel='a' out-channel='assembled'/>
<channel id='b'/> <bridge input-channel='b' out-channel='assembled'/>
<channel id='b'/> <bridge input-channel='c' out-channel='assembled'/>
<channel id='c'/> <bridge input-channel='d' out-channel='assembled'/>
<channel id='assembled'/>
<!-- the router will desicde which jms gateway to be sent -->
<router input-channel='assembled' >
<channel id='to_jms1'/>
<channel id='to_jms2'/>
<jms-outbound-gateway id='jms1' channel='to_jms1'/>
<jms-outbound-gateway id='jms2' channel='to_jms2'/>
i am fresher of Spring Integration, i am confuing one question which i
have multiple channels but now i want to assemble messages from those
channel into single channel, how to implement it ? my senario is that i
have lots of businees modues and each module will corresponding to one
channel, those channels will receive the request then assemble the message
into one single channel , then output to the jms server:
is below code possible ?
<channel id='a'/> <bridge input-channel='a' out-channel='assembled'/>
<channel id='b'/> <bridge input-channel='b' out-channel='assembled'/>
<channel id='b'/> <bridge input-channel='c' out-channel='assembled'/>
<channel id='c'/> <bridge input-channel='d' out-channel='assembled'/>
<channel id='assembled'/>
<!-- the router will desicde which jms gateway to be sent -->
<router input-channel='assembled' >
<channel id='to_jms1'/>
<channel id='to_jms2'/>
<jms-outbound-gateway id='jms1' channel='to_jms1'/>
<jms-outbound-gateway id='jms2' channel='to_jms2'/>
Invoking generic type
Invoking generic type
I am currently following the examples on Java's Generics on the following
page: http://docs.oracle.com/javase/tutorial/java/generics/types.html
public interface Pair<K, V> {
public K getKey();
public V getValue();
}
public class OrderedPair<K, V> implements Pair<K, V> {
private K key;
private V value;
public OrderedPair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() { return key; }
public V getValue() { return value; }
}
Pair<String, Integer> p1 = new OrderedPair<String, Integer>("Even", 8);
OrderedPair<String, Integer> p1 = new OrderedPair<>("Even", 8);
My question is about the lines at the end which create variables. At the
very start, one starts with the pair interface, while another starts with
the OrderedPair class. Is there a difference whether which one is used?
I'm just trying to understand why the code is different.
I am currently following the examples on Java's Generics on the following
page: http://docs.oracle.com/javase/tutorial/java/generics/types.html
public interface Pair<K, V> {
public K getKey();
public V getValue();
}
public class OrderedPair<K, V> implements Pair<K, V> {
private K key;
private V value;
public OrderedPair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() { return key; }
public V getValue() { return value; }
}
Pair<String, Integer> p1 = new OrderedPair<String, Integer>("Even", 8);
OrderedPair<String, Integer> p1 = new OrderedPair<>("Even", 8);
My question is about the lines at the end which create variables. At the
very start, one starts with the pair interface, while another starts with
the OrderedPair class. Is there a difference whether which one is used?
I'm just trying to understand why the code is different.
Creating random alingment for a matrix in matlab
Creating random alingment for a matrix in matlab
How can I create an array with number from 1 to 10 for example without
repeating. Because I will use it to re-aling a matrix's rows. For example
of 1 to 10, I want my output as: 4 1 3 8 2 5 6 7 9 10 But I don't want to
have repated numbers. How can I do that?
How can I create an array with number from 1 to 10 for example without
repeating. Because I will use it to re-aling a matrix's rows. For example
of 1 to 10, I want my output as: 4 1 3 8 2 5 6 7 9 10 But I don't want to
have repated numbers. How can I do that?
Ant detects non-existent package while IDE shows error
Ant detects non-existent package while IDE shows error
My ant build is working fine (compile, jar goals execute without errors).
However, the IDE shows errors in the code. I have tried Eclipse and
IntelliJ-IDEA; both show the same behaviour.
For example, in the following line
import com.google.javascript.rhino.head.ErrorReporter;
my IDE points out that the package com.google.javascript.rhino.head does
not exist. And it is true as I verified that no such package exists at
that location.
I would like to configure my IDE to build correctly so that I can use
debug features. What am I missing here?
My ant build is working fine (compile, jar goals execute without errors).
However, the IDE shows errors in the code. I have tried Eclipse and
IntelliJ-IDEA; both show the same behaviour.
For example, in the following line
import com.google.javascript.rhino.head.ErrorReporter;
my IDE points out that the package com.google.javascript.rhino.head does
not exist. And it is true as I verified that no such package exists at
that location.
I would like to configure my IDE to build correctly so that I can use
debug features. What am I missing here?
Jquery get one or more checkbox value
Jquery get one or more checkbox value
Hello i have html table where i list database result. All database items
have self checkbox with value item id:
<td> <input type="checkbox" id="row" value="<?php echo
$this->escapeHtml($item->id);?>"> </td>
Now i want to take one or more checked item and that value to put in my
url like last param.
<a onclick="return Form.deleteItem(this);" href="<?php echo
$this->url('phonebook', array('action'=>'edit', 'id' => '1'));?>">
<?php echo $this->escapeHtml('Edit');?>
</a>
I want that add value to in url like this.
http://www.example.com/edit/1
So if user check one item and click on edit how to put that value in url
like last param
I try this but dont work:
deleteItem: function(obj) {
$('input[type=checkbox]').change(function(e){
e.preventDefault();
if ($("#row").is(':checked')) {
//read line
var queryString = $("#row").val();
// Loop
var s = $("#row").siblings();
$.each(s, function() {
// see if checked
if ($("#row").is(":checked")) {
queryString += 'OR' + $("#row").val();
}
});
console.log(queryString);
// Append to url
}
});
},
Hello i have html table where i list database result. All database items
have self checkbox with value item id:
<td> <input type="checkbox" id="row" value="<?php echo
$this->escapeHtml($item->id);?>"> </td>
Now i want to take one or more checked item and that value to put in my
url like last param.
<a onclick="return Form.deleteItem(this);" href="<?php echo
$this->url('phonebook', array('action'=>'edit', 'id' => '1'));?>">
<?php echo $this->escapeHtml('Edit');?>
</a>
I want that add value to in url like this.
http://www.example.com/edit/1
So if user check one item and click on edit how to put that value in url
like last param
I try this but dont work:
deleteItem: function(obj) {
$('input[type=checkbox]').change(function(e){
e.preventDefault();
if ($("#row").is(':checked')) {
//read line
var queryString = $("#row").val();
// Loop
var s = $("#row").siblings();
$.each(s, function() {
// see if checked
if ($("#row").is(":checked")) {
queryString += 'OR' + $("#row").val();
}
});
console.log(queryString);
// Append to url
}
});
},
Subscribe to:
Comments (Atom)