Can you use a sieve to generate the prime numbers then add to stack?
As far as your problem. You aren't checking if a number is prime before adding it to the stack what you are doing is checking if some number is evenly divisible by [2,num/2] and if so then add it to the stack. You may want to change your logic or read up on primes a little more. Basically a prime number is a number that is only divisible by 1 and itself. Examples: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29