小编Adi*_*tya的帖子

如何获取基元的最小值和最大值?

i32如何存储变量中的最小值?

// Java Example :
int min = Integer.MIN_VALUE;
Run Code Online (Sandbox Code Playgroud)
// C++ example
int min = INT_MIN;
Run Code Online (Sandbox Code Playgroud)

我想做类似的事情:

let min: i32 = i32_MIN_VALUE;
Run Code Online (Sandbox Code Playgroud)

primitive rust

4
推荐指数
1
解决办法
2606
查看次数

我怎样才能改变一个不可变的集合?

这是我的代码。

我正在尝试创建一个以 i32 作为键、以 HashSets 作为值的 Hashmap。但是当我编译时,我收到一条警告,指出变量(HashSet)不需要是可变的。但我显然正在向 HashSet 插入值。

use std::collections::*;

fn main() {
    let mut map = HashMap::new();
    for i in 0..3 {
// the warning will disappear if I remove the 'mut' keyword
        let mut set = HashSet::new();
        map.insert(i, set);
    }
    
    for (i, set) in &mut map {
        for j in *i..(i+5) {
//here I am inserting values to the hashset , therefore set has to be mutable
            set.insert(j);
        }
    }
    
    for (i, set) in &map {
        println!("{i} …
Run Code Online (Sandbox Code Playgroud)

rust

1
推荐指数
2
解决办法
722
查看次数

delete c in void insert() 打印无限数,如果我将其注释掉,我会得到正确的输出

这个程序在 cpp 中创建并打印一个链接列表 当这个程序运行一个无限的 no。的数字开始在控制台打印

#include <cstdlib>
#include <iostream>
using namespace std;

class Node {
    public:
        int data;
        Node* next;
};

class Node* head = NULL;
int length = 0;
Run Code Online (Sandbox Code Playgroud)

在这个函数中,如果我注释掉 delete c 那么它就起作用了,我不知道为什么 delete c 会导致问题

void insert(int data) {
    class Node* newNode = NULL;
    newNode = new Node();
    newNode->data = data;
    newNode->next = NULL;
    if(head == NULL) {
        head = newNode;
        length++;
    }
    else {
        class Node* c = head;
        while(c->next != NULL) {
        c = c->next;
        } …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
41
查看次数

标签 统计

rust ×2

c++ ×1

primitive ×1