小编J. *_* G.的帖子

如何计算元素大于其后继元素的次数?

我目前正在尝试解决以下练习:

给定一个Ints列表,计算一个元素大于它后面的元素的次数。该练习迫使我不要使用显式递归。

以下是给出的一些示例输出function :: [Int] -> Int

function [1, 2, 3, 4, 5]         == 0  -- only increasing numbers
function [5, 4, 3, 2, 1]         == 4  -- only decreasing numbers

function [2,  1,  3,  1,  0,  4] == 3
--        2 > 1  
--                3 > 1
--                    1 > 0

function [1] == 0 -- no successor
function [ ] == 0 -- no numbers at all
Run Code Online (Sandbox Code Playgroud)

我想以某种方式使用,foldl但经过多次尝试和没有工作的想法我不得不放弃。

如何在不使用递归的情况下计算元素大于其后继元素的次数?

haskell list foldleft

3
推荐指数
1
解决办法
68
查看次数

消息队列问题

该程序应创建一个固定数量的子级(30),并且这些线程应相互通信,以供以后解释。发生错误22:msgsnd和msgrcv行上的参数均无效。抱歉,这是我第一次尝试在C中使用消息队列

现在,我希望父亲首先给孩子发送有关偏好号的消息,每个孩子都应该收到它,并在名为vettorestudenti的数组中写入此信息。在开始做其他事情之前,我必须解决此问题

在定义区域的开头有一个测试代码:



there are some structs:
 struct dati{
        pid_t sender;
        int preferenza;// the father writes a preference number in a queue that should be read by children threads
    };
    struct msgbuf {
            long mtype; //pid destinatario 
            struct dati msglist;

        };
 struct tipostudente { //array that contains info about child process

    int matricola; // ID
    int voto_AdE; //student mark
    int numeroinviti; //number of invitations
    int preferenzaGruppo; // preference
    };
    pid_t *studenti;
//FOLLOW UPDATED CODE
 struct msgbuf coda[POP_SIZE];
    int queue_id = …
Run Code Online (Sandbox Code Playgroud)

c multithreading

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

标签 统计

c ×1

foldleft ×1

haskell ×1

list ×1

multithreading ×1