⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d7r5.cpp

📁 C语言的编程合集!是我自己编的!很有用的!大家可以下载!有意见麻烦大家提出来以便本人及时修改!
💻 CPP
字号:
#include "iostream.h"
#include "fstream.h"
#include "stdlib.h"
#include "conio.h"

void sort2(int n, double ra[], double rb[])
{
	int l,ir,i,j;
	double rra,rrb;
    l = n / 2 + 1;
    ir = n;
    do
	{
        if (l > 1)
		{
            l = l - 1;
            rra = ra[l];
            rrb = rb[l];
		}
        else
		{
            rra = ra[ir];
            rrb = rb[ir];
            ra[ir] = ra[1];
            rb[ir] = rb[1];
            ir = ir - 1;
            if (ir == 1)
			{
                ra[1] = rra;
                rb[1] = rrb;
                return;
            }
        }
        i = l;
        j = l + l;
        while (j <= ir)
		{
            if (j <= ir)
			{
				if (j < ir)
				{
                    if (ra[j] < ra[j + 1])
					{
						j = j + 1;
					}
                }
                if (rra < ra[j])
				{
                    ra[i] = ra[j];
                    rb[i] = rb[j];
                    i = j;
                    j = j + j;
				}
                else
				{
                    j = ir + 1;
                }
            }
        }
        ra[i] = rra;
        rb[i] = rrb;
    }while(1);
}

void main()
{
    //program d7r5
    //for routine sort2
    double a[101], b[101];
	int i,j;
	ifstream fin;
	fin.open("d:\\vc常用数值算法集\\data\\tarray.dat",ios::in|ios::nocreate);
	if (!fin)
	{
		cerr<<"could not open d:\\vc常用数值算法集\\data\\tarray.dat"<<endl;
		exit(1);
	}
	for (i=1; i<=100; i++)
	{
		fin>>a[i];
	}
	fin.close();
    //generate b-array
    for (i = 1; i<=100; i++)
	{
        b[i] = i;
    }
    //sort a and mix b
    sort2(100, a, b);
    cout<<"After sorting A and mixing B, array A is:"<<endl;
    for (i = 1; i<=10; i++)
	{
        for (j = 1; j<=10; j++)
		{
			cout.width(7);
			cout.setf(ios::left);
            cout<<a[10 * (i - 1) + j];
        }
        cout<<endl;
    }
	cout<<endl;
    cout<<"...and array b is:"<<endl;
    for (i = 1; i<=10; i++)
	{
        for (j = 1; j<=10; j++)
		{
			cout.width(7);
			cout.setf(ios::left);
            cout<<b[10 * (i - 1) + j];
        }
        cout<<endl;
    }
    cout<<"press any key to continue..."<<endl;
    getch();
    //sort b and mix a
    sort2(100, b, a);
    cout<<"After sorting A and mixing B, array A is:"<<endl;
    for (i = 1; i<=10; i++)
	{
        for (j = 1; j<=10; j++)
		{
			cout.width(7);
			cout.setf(ios::left);
            cout<<a[10 * (i - 1) + j];
        }
        cout<<endl;
    }
	cout<<endl;
    cout<<"...and array B is:"<<endl;
    for (i = 1; i<=10; i++)
	{
        for (j = 1; j<=10; j++)
		{
			cout.width(7);
			cout.setf(ios::left);
            cout<<b[10 * (i - 1) + j];
        }
        cout<<endl;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -