Friday 15 February 2013

Java list using arrays or any listing method -


Friends, I have the test that I am having difficulty in doing this because I did not understand what I am just one Using the Arrange of Switch Statement I'm still new to Java so please help. Here's the question.

  Write a Function: Category IntList {Public Full Value; Public IntList Next; } Class solutions {public full solution (IntList L, int M); }   

that, in a single link list L in the N integer and a positive integer

that one Single link list L gets an integer and a positive integer M , values ​​stored in the M-th element, in the list, counting from the end While doing this, assuming that the last element in the list is index 1 is to return the function a "1" if it is not possible to return such a value, for example , L has been :

  L = 1 - & gt; 2 - & gt; 3 - & gt; 4   

and M = 2 should return the function to 3 , because the value in the second element of the count from the end of the list is 3 .

If I am not mistaken then you need to write the program which will return the last element from a link list I - If this is a link alone list, then you need a key indicator that you have a major indicator that is called intralastic head. The following element has the code to find Kth

  the public int solution (IntList head, int k) {IntList temp = head; Int count = 0; While (count! = K) {if (temp == null) {return -1; } Temp = temp.next; } While (temp! = Null) {head = head.next; Temp = temp.next; } Return Head. value; }   

Not tested the entire error but it should work.

No comments:

Post a Comment