public void log
    (){
        if(start==null)
            System.out.println("List is empty..");
        else{
        Node temp=start;
        System.out.print("->");
        //get rid of each user with a similar method but with a random user removed....
        while(temp.next!=start
                )
        {



            int  r = rand.nextInt(2) ;

            if(r==0)
            {
                deleteAt(counter);
                System.out.println("Is Logged Off "+temp.data);
            }
            else if(r==1)
            {
                System.out.println("Is Logged on "+temp.data);

            }


            counter++;

            temp=temp.next;




        }



    }
}
    public void deleteAt(int position){
        Node current=start;
        Node previous=start;
        for(int i=0;i<position;i++){
            if(current.next==start)
                break;
            previous=current;
            current=current.next;
        }

        if(position==0)
            deleteFirst();
        else
            previous.next=current.next;
        count--;
    }
    public void deleteFirst() {
        Node temp=start;
        while(temp.next!=start){
            temp=temp.next;
        }
        temp.next=start.next;
        start=start.next;
        count--;
    }
    public int size(){
        return count;
    }

I want to loop though a circular list, on each occasion i randomly generate either a 1, or a 0, if it's a 0, I delete that user from the list, if it's a 1 I continue on, leaving that user logged in, essentially mimicing logging on and off. How do I do this? Every time I try it seems to come very close but not quite work, what am I doing wrong??

This article has been dead for over six months. Start a new discussion instead.