/*Chris Poon
 *
 *template for CardList.java (be sure to rename this file if you
 *use it directly).
 *only shuffle() and hasNodes() is written for you.
 *you still have to write the remaining methods
 *that are prototyped.
 */
package VideoPoker;

import java.util.Random;

class CardList{
       CardNode head;
       
       public CardList(){
           //default constructor
           head=null;
       }
       // any other constructors...
       // ...
       
       public void insert(CardNode somecard){
       // public method to insert somecard into _this_ CardList
       }
       
       // of course, you'll probably need another remove method to
       // delete a specific node (from the players hand).
       public CardNode remove(){
       // public method to remove top card of _this_ CardList
       }
       
       public boolean hasNodes(){
       //public method to return if there are more Nodes
            return (head!=null);
       }
       
       // any other methods.. for sorting, etc...
       // ...
       
       public void shuffle(){
        // public method to shuffle up _this_ CardList. 
        // assumes _this_ is not an empty list and contains multiple nodes.
            CardList top=new CardList();
            CardList bottom=new CardList();
            Random r=new Random();
            int n=r.nextInt(3)+7;
            
            while (n>0){
                while (this.hasNodes()){
                    if (r.nextInt(2)==0){
                        top.insert(this.remove());
                    }
                    else
                        bottom.insert(this.remove());
                }

                while (top.hasNodes()){
                    this.insert(top.remove());
                }
                while (bottom.hasNodes()){
                    this.insert(bottom.remove());
                }
                n--;
            }
        
       }
}
