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

📄 0.cpp

📁 这是数据结构的活动结点的算法
💻 CPP
字号:
// 设计三--活动安排.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
#include<ctime>
#include <stdlib.h>

const int num=20;

typedef int KeyType;
using namespace std;
struct DataType 
{
	KeyType key;
};

int _tmain(int argc, _TCHAR* argv[])
{
	int i,j;
	int count=0;
	time_t t;
	 srand ((unsigned)time(&t));
	 cout<<" 随机数 from 0 to 20\n";
	 DataType a [num][2];
     for(i=0; i<num; i++)
        for(j=0;j<2;j++)
	 {   
		 a[i][j].key=rand() % 20;
		 cout<<a[i][j].key <<" ";
		 count++;
	 }
		cout <<"产生的元素个数个数为:" <<count <<endl;
		//int i,j;
	DataType temp;
	for (i=0;i<num-1;++i)
	{ 
        temp=a[i+1][1];
		j=i;
		while(j>-1&&temp.key<=a[j][1].key)
		{
			a[j+1][1]=a[j][1];
			a[j+1][0]=a[j][0];

			j--;
		}
		a[j+1][1]=temp;
	}
	cout <<"该数组fi的数值为:"<<endl;
	for(i=0; i<num; i++)
	cout << a[i][1].key <<" ";
	cout <<"该数组si的数值为:"<<endl;
	for(i=0; i<num; i++)
    cout << a[i][0].key <<" ";
	bool A[num];
	A[0]=true;
       j=0;
	for(i=1;i<num;i++)
	{
		if(a[i][0].key>=a[j][1].key)
		 {
			 A[i]=true;
			 j=i;
		 }
		 else A[i]=false;
	}
	cout <<"该活动有:" <<endl;
	for(i=0;i<num;i++)
		if(A[i]==true)
			cout<<i+1 <<" ";
		int ab;
		cin>>ab;

	return 0;
}

⌨️ 快捷键说明

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