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

📄 misc.cc

📁 模拟器提供了一个简单易用的平台
💻 CC
字号:
/************************************************** *  File: misc.cc  Author: Suman Banerjee <suman@cs.umd.edu>  Date: 15th March, 2001  Terms: GPL  Narada implementation in myns  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ***************************************************/#include <stdio.h>#include <stdlib.h>#include <assert.h>#include <randomize.h>int get_rand (int max) {//   return (rand() % max);   return (get_generic_random() % max);}/* Returns a set *count* numbers between 0 and max-1 *//* The return list is sorted in ascending order */int * get_rand_set (int count, int max) {  assert (count <= max);  bool *ret_bools = new bool [max];  for (int i = 0; i < max; i++)    ret_bools[i] = false;  for (int i = 0; i < count; i++) {    int nonconsec_final_index = get_rand(max - i);    int nonconsec_running_index = 0;    for (int j = 0; j < max; j++) {      if (ret_bools[j] == false) {        if (nonconsec_running_index == nonconsec_final_index) {          ret_bools[j] = true;          break;        }        nonconsec_running_index ++;      }    }  }  int * ret_nums = new int [count];  int x = 0;  for (int i = 0; i < max; i++) {    if (ret_bools[i] == true) {      assert (x < count);      ret_nums[x] = i;      x++;    }  }  assert (x == count);  delete [] ret_bools;  return ret_nums;}void * safe_malloc (int size) {  void *p = malloc (size);  if (p == NULL) {     perror("malloc:");     exit(-2);     return NULL;  }  return p;}

⌨️ 快捷键说明

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