linked list assignment
Hello, im quite new to java, and I have a problem with a piece of code.
This is the code so far, I hope u can help me with the code or with hints
Regards Tim
public class DataStructuren
{
/* STEP 1
Write the code for a method make() which creates and fills a 4 x 4 array with values such that the
array elements of myArray[j] contain the values of the expression (i+j)*(i-j)/2
*/
public void make()
{
} // end method make()
/* STEP 2
Write the code for a method singleDim() which converts the myTable array to a single dimension array
newTable with 16 elements
*/
public void singleDim()
{
} // end method singleDim()
/* STEP 3
Write the code for a method fillTree() which inserts the unique values from uniArray into a binary tree
*/
public void fillTree() // Step 3
{
// you can use methods from the Deitel & Deitel class 'tree.java'
}
/* STEP 4
Write the code to build a linked list with the sorted values from the binary tree. Take a look at the code
in Deitel & Deitel class tree.java. Add a list object and a new method to this class to build the linked list.
*/
public void buildList()
{
// call methods from tree.java
}
/* STEP 5
Write code to print the linked list (you can use the print() method from class list.java)
*/
public void listTree() // Step 5
{
}
public static void main(String args[])
{
DataStructuren toetsOpdracht = new DataStructuren();
toetsOpdracht.make();
toetsOpdracht.singleDim();
toetsOpdracht.fillTree();
toetsOpdracht.buildList();
toetsOpdracht.listTree();
}
} // end class DataStructuren
ok im here so far,
most of 1 is done but \ how to add the values of the expression?
public class DataStructuren
{
/* STEP 1
Write the code for a method make() which creates and fills a 4 x 4 array with values such that the
array elements of myArray[j] contain the values of the expression (i+j)*(i-j)/2
*/
public void make()
{
int b[][];
myarray = new int[ 4 ][ 4 ];
System.out.println("step 1");
} // end method make()
/* STEP 2
Write the code for a method singleDim() which converts the myTable array to a single dimension array
newTable with 16 elements
*/
public void singleDim()
{
} // end method singleDim()
/* STEP 3
Write the code for a method fillTree() which inserts the unique values from uniArray into a binary tree
*/
public void fillTree() // Step 3
{
// you can use methods from the Deitel & Deitel class 'tree.java'
}
/* STEP 4
Write the code to build a linked list with the sorted values from the binary tree. Take a look at the code
in Deitel & Deitel class tree.java. Add a list object and a new method to this class to build the linked list.
*/
public void buildList()
{
// call methods from tree.java
}
/* STEP 5
Write code to print the linked list (you can use the print() method from class list.java)
*/
public void listTree() // Step 5
{
}
public static void main(String args[])
{
DataStructuren toetsOpdracht = new DataStructuren();
toetsOpdracht.make();
toetsOpdracht.singleDim();
toetsOpdracht.fillTree();
toetsOpdracht.buildList();
toetsOpdracht.listTree();
}
} // end class DataStructuren
ok a bit of a change
public void make()
{
int myArray[][];
myArray = new int[ 4 ][ ];
myArray[ 0 ] = new int [ 4 ];
myArray[ 1 ] = new int [ 4 ];
myArray[ 2 ] = new int [ 4 ];
myArray[ 3 ] = new int [ 4 ];
System.out.println("step 1");
} // end method make()
why not use int. i use int cause u can devide it by 2 with strings u can't (thats what i learned)