小编mon*_*dle的帖子

A.length和A.heap-size有什么区别?

我有一个关于堆排序的问题.它在算法书中说明A.heap-size<= A.length 我不理解两者之间的区别.如果数组表示堆,为什么有可能A.heap-size小于A.length.我知道这A.heap-size表示堆内元素的数量,为什么它不完全只等于数组中的项数?

arrays algorithm heap data-structures

14
推荐指数
2
解决办法
7909
查看次数

错误,缺少终止字符

我有这个缺少终止的角色,但我不确定它想要什么或需要什么.我相信它在第二次循环的内部.可以做些什么来解决这个问题.我正在尝试输入一个带有一串路径的文本文件.然后从那里我解析这个字符串并将其放到链接列表中.然后创建一个搜索功能.

文本文件:path.txt

a/a1.txt
a/a2.txt
a/b/b3.txt
a/b/b4.txt
a/c/c4.txt
a/c/c5.txt
a/c/d/d6.txt
a/c/d/g
a/c/d/h
a/c/e/i/i7.txt
a/c/f/j/k/k8.txt
Run Code Online (Sandbox Code Playgroud)

码:

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct sMyPath{
        char *element;
        struct sMyPath *next;
} tMyPath;


int main(void)
{
        FILE *pFile;
        pFile = fopen("path.txt", "r");
        char inputstr[1024];
        tMyPath *curr, *first = NULL, *last = NULL;

//get the text file, and put it into a string inputstr

        if (pFile != NULL)
        {
                while(!feof(pFile))
                {
                        fgets(inputstr, sizeof(inputstr), pFile);
                }
        fclose(pFile);
        }
        else
        {
                printf("Could not open the file.\n"); …
Run Code Online (Sandbox Code Playgroud)

c syntax-error

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

错误:分配只读位置

当我编译这个程序时,我一直收到这个错误

example4.c: In function ‘h’:
example4.c:36: error: assignment of read-only location
example4.c:37: error: assignment of read-only location
Run Code Online (Sandbox Code Playgroud)

我认为它与指针有关.我该如何解决这个问题.它是否与指向常量指针的常量指针有关?

#include <stdio.h>
#include <string.h>
#include "example4.h"

int main()
{
        Record value , *ptr;

        ptr = &value;

        value.x = 1;
        strcpy(value.s, "XYZ");

        f(ptr);
        printf("\nValue of x %d", ptr -> x);
        printf("\nValue of s %s", ptr->s);


        return 0;
}

void f(Record *r)
{
r->x *= 10;
        (*r).s[0] = 'A';
}

void g(Record r)
{
        r.x *= 100;
        r.s[0] = 'B';
}

void h(const …
Run Code Online (Sandbox Code Playgroud)

c compiler-errors

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

错误:表达式必须有一个类类型

我收到错误:表达式必须有一个类类型首先,我不明白为什么我会收到这个错误。我创建并反对并使用它。在我的主要:

#include "Worker.h"

int main()
{

    Worker myWorker();
    myWorker.inputInfo();
    myWorker.displayPayBarGraph();

}
Run Code Online (Sandbox Code Playgroud)

工人.h

//Worker.h
//Definition of class Workers
//Member functions are defined in Worker.cpp


//Worker class defintion 

class Worker
{
public:
    Worker();               //constructor initializes worker type

    void inputInfo();           //attains worker information
    void displayPayBarGraph();  //prints a bar graph representation of the pay

private:

    int workerCode;     //worker type
    //PAY FOR EACH WORKER
    double code1pay;            //manager
    double code2pay;            //hourly workers
    double code3pay;            //commission workrs
    double code4pay;            //pieceworkers

    int hourlyWorkerPay(double, int);   //returns the pay of …
Run Code Online (Sandbox Code Playgroud)

c++ class object

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

为什么每次运行此程序时输出的顺序都不同?

为什么每次运行此程序时输出的顺序都不同?是否由于多个线程同时尝试访问共享资源.因此,线程执行的方式是随机的吗?

我的输出

java MyThreadExample Hello from thread 1 Hello from thread 3 Hello from thread 4 Hello from thread 2

java MyThreadExample Hello from thread 1 Hello from thread 3 Hello from thread 4 Hello from thread 4

java MyThreadExample
Hello from thread 1
Hello from thread 4
Hello from thread 3
Hello from thread 2
Run Code Online (Sandbox Code Playgroud)

码:

import java.io.*;
import java.lang.*;

class MyThreadExample {

public static void main(String[] args) {
   HelloThread ht1 = new HelloThread(1);
   HelloThread ht2 = new HelloThread(2); …
Run Code Online (Sandbox Code Playgroud)

java multithreading operating-system

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

为什么我的文字区域不会显示出来

我正在尝试实现一个程序,客户端将向服务器端发送修复消息,而我在服务器端的UI将在文本区域显示FIX消息.但是,当我启动程序时,除文本区域外,将显示文本字段和所有标签.当我尝试从客户端发送消息时,除文本区域外,一切都有效.

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.util.Scanner;
    import java.util.StringTokenizer;
    import java.awt.*;        // using AWT containers and components
    import java.awt.event.*;  // using AWT events and listener interfaces

    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;

    public class TcpServerCompareCSV extends Frame implements ActionListener , WindowListener  {        

           private Label lblPort;       // declare component Label
           private TextField tfPort;    // declare component TextField     
           private int port;            // port number

           private Label lblLocation;       // declare component Label …
Run Code Online (Sandbox Code Playgroud)

java io user-interface swing awt

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

使用多个密钥从CSV文件创建字典

假设我有一个csv文件,并且想要一个每个值有多个键的字典.

示例csv:

col1,col2,col2,col4,col5
a1,b1,c1,d1,e1
a2,b2,c2,d2,e2
a3,b3,c3,d3,e3
Run Code Online (Sandbox Code Playgroud)

您将如何创建字典,以便专门提取列1,2,3作为键并使用col5作为值.

输出:

{(a1,b1,c1):e1 , (a2,b2,c2):e2 , (a3,b3,c3):e3 }
Run Code Online (Sandbox Code Playgroud)

有没有方法可以做到这一点?

python csv dictionary

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

澄清glFrustum,以及为什么我看不到图像

目前我的glFrustum设置为

glFrustum(0, 100.0, 0, 100.0, -50, 50);
Run Code Online (Sandbox Code Playgroud)

我的图像是一个矩形立方体,尺寸:当形状的尺寸小于观察盒时,为什么我看不到图像?

//top
    glBegin(GL_POLYGON);
        glVertex3f(25, 60, 25);
        glVertex3f(75, 60, 25);
        glVertex3f(75, 60, -25);
        glVertex3f(25, 60, -25);
    glEnd();

    //bottom
    glBegin(GL_POLYGON);
        glVertex3f(25, 55, 25);
        glVertex3f(75, 55, 25);
        glVertex3f(75, 55, -25);
        glVertex3f(25, 55, -25);
    glEnd();

    //front
    glBegin(GL_POLYGON);
        glVertex3f(25, 55, 25);
        glVertex3f(75, 55, 25);
        glVertex3f(75, 60, 25);
        glVertex3f(25, 60, 25);
    glEnd();

    //back
    glBegin(GL_POLYGON);
        glVertex3f(25, 60, -25);
        glVertex3f(75, 60, -25);
        glVertex3f(75, 55, -25);
        glVertex3f(25, 55, -25);
    glEnd();
Run Code Online (Sandbox Code Playgroud)

c++ opengl graphics dimension

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

错误:错误1错误LNK2019:函数___tmainCRTStartup中引用的未解析的外部符号_WinMain @ 16

我该如何解决此错误:

Error 1 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup 
Run Code Online (Sandbox Code Playgroud)

我还定义了cai.cpp中的所有函数.但是由于代码行太多,我没有上传它.我确实将.h文件包含在cai.cpp中.我对这个错误的问题感到困惑.

main.cpp文件

#include "cai.h"

int main()
{
    CAI test;
    test.StartTest();

}
Run Code Online (Sandbox Code Playgroud)

cai.h文件

class CAI
{
public:

    void StartTest();
    bool AskRandomMultiplicationQuestion();
    bool AskRandomDivisioQuestion();


private:
    void PrintRandomGoodJob();
    void PrintRandomEncouragementMessage();
    int ChooseRandomNumber();
    void PrintTestSummary(int, int, int);

};
Run Code Online (Sandbox Code Playgroud)

c++ error-handling linker-errors

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