Click here to Skip to main content
15,888,984 members
Home / Discussions / Java
   

Java

 
AnswerRe: If string is a immutable class then how come it is allowing us to make changes ? Pin
Luc Pattyn23-Apr-11 7:25
sitebuilderLuc Pattyn23-Apr-11 7:25 
GeneralRe: If string is a immutable class then how come it is allowing us to make changes ? Pin
shiva.kore23-Apr-11 7:45
shiva.kore23-Apr-11 7:45 
GeneralRe: If string is a immutable class then how come it is allowing us to make changes ? Pin
CoderForEver23-Apr-11 20:40
CoderForEver23-Apr-11 20:40 
QuestionDesktop notification application in java Pin
krutikaji22-Apr-11 7:32
krutikaji22-Apr-11 7:32 
AnswerRe: Desktop notification application in java Pin
jschell22-Apr-11 14:02
jschell22-Apr-11 14:02 
GeneralRe: Desktop notification application in java Pin
Richard MacCutchan22-Apr-11 22:40
mveRichard MacCutchan22-Apr-11 22:40 
GeneralRe: Desktop notification application in java Pin
TorstenH.25-Apr-11 11:58
TorstenH.25-Apr-11 11:58 
QuestionIn-place Merge-Sort with doubly linked list Pin
Manfr3d22-Apr-11 1:35
Manfr3d22-Apr-11 1:35 
Hello guys,

I have to write an in-place version of Merge-Sort which works on doubly linked lists for university.
This wouldn't be the problem, but there are a few conditions to meet.
- the algo must work in-place (additional memory usage in O(log n))
- I cannot create new list elements or entire lists, just copies (ListElement left = new List Element() isn't possible but ListElement left = first is possible)
- the algo should be recursive, but this is not necessary
- each call of the algo must return a head pointer to the first element of the sub-list
- the merge part must also return a head pointer
public DoublyLinkedList mergesort(DoublyLinkedList in, int numOfElements) {
		
        if (numOfElements > 1) {

            DoublyLinkedList firstLeft = in;
            DoublyLinkedList firstRight = in;

            for ( int i = 0; i < numOfElements / 2; i++ ) {
                firstRight.first = firstRight.first.next;
            }

            DoublyLinkedList left = mergesort ( firstLeft, (int)Math.floor(numOfElements / 2 ) );
            DoublyLinkedList right = mergesort ( firstRight, (int)Math.ceil(numOfElements / 2 ) );
            return merge ( left, right );

        } else {
            return in;
        }

}

My problem is that I'm somehow stuck right at the beginning. The algo itself shouldn't be the problem, but the additional conditions make the whole thing quite difficult for me.
Of course I've already searched for useful algos or something, but I didn't find anything.

Thanks in advance for your help and best wishes,
Manfred
AnswerRe: In-place Merge-Sort with doubly linked list Pin
TheLaughingManAnDerTU25-Apr-11 9:03
TheLaughingManAnDerTU25-Apr-11 9:03 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
Manfr3d25-Apr-11 9:16
Manfr3d25-Apr-11 9:16 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
TheLaughingManAnDerTU25-Apr-11 10:29
TheLaughingManAnDerTU25-Apr-11 10:29 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
Manfr3d25-Apr-11 12:20
Manfr3d25-Apr-11 12:20 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
JavaStudent_LA25-Apr-11 16:11
JavaStudent_LA25-Apr-11 16:11 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
Manfr3d25-Apr-11 22:46
Manfr3d25-Apr-11 22:46 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
TheLaughingManAnDerTU26-Apr-11 6:04
TheLaughingManAnDerTU26-Apr-11 6:04 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
Manfr3d27-Apr-11 0:05
Manfr3d27-Apr-11 0:05 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
JavaStudent_LA29-Apr-11 15:17
JavaStudent_LA29-Apr-11 15:17 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
Manfr3d30-Apr-11 3:41
Manfr3d30-Apr-11 3:41 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
JavaStudent_LA3-May-11 16:26
JavaStudent_LA3-May-11 16:26 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
Manfr3d3-May-11 21:58
Manfr3d3-May-11 21:58 
GeneralMessage Removed Pin
4-May-11 4:44
JavaStudent_LA4-May-11 4:44 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
Manfr3d4-May-11 7:32
Manfr3d4-May-11 7:32 
GeneralRe: In-place Merge-Sort with doubly linked list Pin
JavaStudent_LA8-May-11 11:41
JavaStudent_LA8-May-11 11:41 
Questionmysql to oracle conversion tool Pin
ankit.mathurs21-Apr-11 16:39
ankit.mathurs21-Apr-11 16:39 
AnswerRe: mysql to oracle conversion tool Pin
TorstenH.21-Apr-11 22:56
TorstenH.21-Apr-11 22:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.