Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (ajprincess):

Note:This is not a question. I jst like to share some methods in java which I feel will be helpful. It seems they are most commonly needed ones.:)

OpenStudy (ajprincess):

The method to reverse elements in linked list public void reverse() { Link current=first; Link forward; Link previous = null; while(current!=null) { forward=current.next; current.next = previous; previous=current; current=forward; } first=previous; } The method to find the middle element in a linked list public Link midelement() { Link current = first; Link middle =first; int length = 0; while(current!=null) { length++; if(middle != current && length%2 != 0) { middle=middle.next; } current=current.next; } return middle; } The method to find the size of the linked list public int size() { Link current=first; int length=0; while(current!=null) { length++; current=current.next; } return length; } The method to find the nth element in a linked list public Link nthElement(int n) { Link current = first; for(int length = 1;length< n;length++) { current = current.next; } return current; }

OpenStudy (ajprincess):

The method for reversing elements that I posted here is non recursive method

OpenStudy (aravindg):

I havent studied java yet put the code looks interesting :)

OpenStudy (konradzuse):

http://docs.oracle.com/javase/6/docs/api/java/util/LinkedList.html A lot of these already exist in the API. The API is your most powerful tool.

OpenStudy (nincompoop):

if you're using python, list.reverse() exists as a function.

OpenStudy (anonymous):

you would better share whole class, but yeah much things already exists in API however its good to write it yourself for practise or even better do that in C >:) have fun with pointers

OpenStudy (ajprincess):

thnx:)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!