[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[jfriends] Re: [jfriends] Re: swap





On Fri, 29 Jan 1999 19:43:44 +0900
Kazuya Maebashi <maebashi@xxxxxxxxxx> wrote:

> ===============================================================
>    『 格安広告掲載 』  (15万通 1万円  0.067円/通)   
> 
>                  インターネットで買物を!
>            このMLは広告費で成り立っております!
>   広告の掲載は http://www.dns-ml.co.jp/ad-proto.html \10,000〜
> ===============================================================
> 
> 前橋です。
> 
> >>swapが作れるものなら作りたい、という要望は、プログラマの側
> >>からすれば自然なものに思えます。
> 
Javaの場合のswapはこんな感じでは

//使用方法
Pair P1=new Pair(x,y);

     P1.swap();




//クラス定義
class  Pair{

    int x;
    int y;
    public void Pair(x,y){
                     this.x=x;
                     this.y=y;
    }
   public void swap{
                 int tmp=this.x;
                 this.x=this.y;
                 this.y=x;
   }
   public int getLeft(){
       return this.x;
   }
   public int getRight(){
       return this.y;
   }
}