id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

tmhscs@gmail.com queues > queue_evensBeforeOdds
prev  |  next  |  chance

Given a queue of integers, reorder the queue so that all of the even integers come before all of the odd integers. The even numbers should remain in their original order, and the odd numbers should remain in their original order. Use one auxiliary queue to solve this problem. (Hint: Put all odds into the auxiliary queue and move them back in).

 Start your code with:
  Queue<Integer> queue1 = new LinkedList<Integer>(list);
  Queue<Integer> queue2 = new LinkedList<Integer>();

queue_evensBeforeOdds([1, 2, 3, 4, 5, 6]) → [2, 4, 6, 1, 3, 5]
queue_evensBeforeOdds([1, 2, 3]) → [2, 1, 3]
queue_evensBeforeOdds([1, 1, 2, 2, 3, 3, 4, 4]) → [2, 2, 4, 4, 1, 1, 3, 3]

...Save, Compile, Run (ctrl-enter)

public Queue<Integer> queue_evensBeforeOdds(List<Integer> list) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy