12 Mart 2010 Cuma

C++ da Swap ve Temp Kullanımı

//www.ethemsulan.com
#include <cstdlib>
#include <iostream>
using namespace std;
void swap(int &x,int &y){
     int temp;
     temp=x;
     x=y;
     y=temp;
     }
void swap2(int *m,int *n){
     int temp;
     temp=*m;
     *m=*n;
     *n=temp;
     }
void swap3(int a,int b){
          int temp;
          temp=a;
          a=b;
          b=temp;
          }
int main(int argc, char *argv[])
{
    int f=225,y=11;
    cout<<f<<' '<<y<<endl;
    swap3(f,y);
cout<<"after fonk is call"<<endl<<f<<' '<<y<<endl<<endl;
    int i,j;
    i=12;
    j=210;
    cout<<i<<' '<<j<<endl;
    swap(i,j);
    cout<<"after call fonk: "<<endl<<i<<' '<<j<<endl;
    cout<<endl<<endl;
    int t=25,h=521;
    cout<<t<<' '<<h<<endl;
    swap2(&t,&h);
    cout<<"after call fonk: "<<endl<<t<<' '<<h<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

Hiç yorum yok:

Yorum Gönder