데이터 구조 링 링크 (조세 프 링)

13002 단어 데이터 구조
package com.    ;

import java.util.Scanner;

public class     _     {
    // n      ,   1    。  m      ( 1 3  ),   k      .
    //                。         。
    //     (    ) -----                      ,hahahhah
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        YouXi youXi = new YouXi(n,1,3);
        youXi.sheng();
        youXi.out();
    }
}
class YouXi{
    public int n ;
    public int m ;
    public int k ;
    public Boy is ; //           
    public Boy ok ; //            
    public YouXi(int n, int m, int k) { //  n       m       k  
        this.n = n;
        this.m = m;
        this.k = k;
    }
    public void sheng(){  //      
        for(int i=1;i<=n;i++){ //  n   
            if(i==1){
                is = new Boy(i);
                ok = is ;
                is.next = is ;
            }else{
                ok.next = new Boy(i);
                ok = ok .next ;
                ok.next = is ;
            }
        }
        for(int i=0;i<m-1;i++){ //           
            is = is.next;
            ok = ok.next;
        }
    }
    public void out(){
        while(is!=ok){
            for(int i=0;i<k-1;i++){
                is = is.next;
                ok = ok.next;
            }
           // System.out.println(is);
            is = is.next;
            ok.next = is;
        }
        System.out.println(is);
    }
    public void printf(){ //      
        if(is==null)    return ;
        Boy temp = is ;
        for(int i=0;i<n;i++){
            System.out.println(temp);
            temp = temp.next ;
        }
    }
}
class Boy{   //  
    public int id ; //  
    public Boy next ;

    public Boy(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return String.valueOf(this.id);
    }
}

좋은 웹페이지 즐겨찾기