View Single Post
Old 10-01-2012, 08:58 PM   PM User | #1
Spartan
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Spartan is an unknown quantity at this point
Question Palindrome using stack,queue

Need some help with a little coding problem.
I need to check if it is a Palindrome using a queue and a stack, by implementing a method that tests whether a sequence of numbers is a palindrome, that is, equal to the sequence in reverse.
the code in [...] is My Code, while everything else is unchangeable any help is appreciated.
Code:
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class QueueStackUtil
{
   public static boolean isPalindrome(int[] values)
   {
      Queue<Integer> queue = new LinkedList<Integer>();
      Stack<Integer> stack = new Stack<Integer>();
      for (int s : values)
      {
         // insert s into the queue and stack
	[//*MyCode//ins instack
		s[++queue]=values;
	//ins in queue
		s[++stack]=values;]
      }
      while (queue.size() > 0)
      {
        [MyCode// remove an element from the queue
         	if(!isPaindrome()){
		for(int i=0; i<tail;i++)
		queue[i] = queue[i+1];
		tail--;
		}
         // remove an element from the stack
		if(!isPalindrome()) stack--;
         
         // compare the removed elements
		if(stack==queue)
		!isPalindrome]

      }
      return true;
   }
}
Spartan is offline   Reply With Quote