Thursday 15 April 2010

java - Non-recursive Merge Sort using Stacks -



java - Non-recursive Merge Sort using Stacks -

i'm working on assignment supposed write mergesort using stacks! have pretty thought on how stacks , mergesort works, not sure how finish code stacks. i've set base of operations case, , here i'm trying utilize in-place method theoretically split array without creating new 1 changing markers. pretty new , unsure of how should proceed.. think sort of thing i'm going :

base case --> pc = 1

if (callstack.peek().pc == 1) { if (callstack.peek().start == callstack.peek().stop) { //length <=1 callstack.pop(); //either done, or array length 1 merge(a, callstack.peek().start, callstack.peek().mid, callstack.peek().stop); if (callstack.empty()){ break; } callstack.peek().pc++; } else { callstack.peek().pc++; } continue; }`

any left divided array --> pc = 2 right divided array --> pc == 3

int mid = (callstack.peek().stop-callstack.peek().start)/2; if (callstack.peek().pc == 2) { if (callstack.peek().start != callstack.peek().stop) { current = new programframe(callstack.peek().start, callstack.peek().mid, 1); callstack.push(current); continue; } } if (callstack.peek().pc == 3) { if (callstack.peek().start != callstack.peek().stop) { current = new programframe(callstack.peek().mid+1, callstack.peek().stop, 1); callstack.push(current); continue; } }

the merged of both --> pc ==4

if (callstack.peek().pc == 4) { merge(a, callstack.peek().start, callstack.peek().mid, callstack.peek().stop);

callstack.pop(); if (!callstack.empty()) { if (callstack.peek().pc == 2) callstack.peek().start callstack.peek().mid; //help?? if (callstack.peek().pc == 3) callstack.peek().mid+1, callstack.peek().stop; //help?? callstack.peek().pc++; continue;

i'm sorry such long post :( unsure of how prepare , how go on it...

** merge , programeframe okay, if need see them can send them too!

java stack mergesort

No comments:

Post a Comment