We can do it by just having an extra pointer variable which will store either rightmost 2's *next node* or left most 2's *previous node*(as it is doubly linked list)..now start traversing through rear end , if u get 1 , send it to front..if u get 3 send it to rear , and if u get 2 the insert it between last 2 and 3(using rightmost 2's *next node*) or last 1 and 2(left most 2's *previous node*)!... e.g. front -> 1->2->3->1->1->1->2->3->2 <-rear iteration1 : front -> 1->2->3->1->1->1->2->3->2 <-rear // u get 2 its ok.. as its first turn iteration2 : front -> 1->2->3->1->1->1->2->2->3 <-rear // send 3 to rear , save last 2's next node in temporary pointer now carry on.. i hope u got what i meant!? On Aug 2, 1:27 am, Lokesh <[email protected]> wrote: > A doubly linked list has only 1,2 and 3 as values in nodes ..sort the > linked list > > Ex. > Q: 1->2->3->1->1->1->2->3->2 > O/P: 1->1->1->1->2->2->2->3->3 > > Dont change the original LL.
-- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
