我在声明和初始化char数组时遇到问题.它始终显示随机字符.我创建了一小段代码来显示我在更大的程序中尝试的内容:
class test
{
private:
char name[40];
int x;
public:
test();
void display()
{
std::cout<<name<<std::endl;
std::cin>>x;
}
};
test::test()
{
char name [] = "Standard";
}
int main()
{ test *test1 = new test;
test1->display();
}
Run Code Online (Sandbox Code Playgroud)
对不起,如果我的格式不好,我几乎无法弄清楚这个网站,更不用说如何修复我的代码:(
我正在上一门java课,但已经离开了一段时间.
试图让这个排序程序工作:
import java.util.*;
public class Assignment1
{
private int[] nums;
private int[] ast;
private int n;
public void sort(int[] vals)
{
this.nums = vals;
n = vals.length;
this.ast = new int[n];
merges(0, n - 1);
}
private void merges(int bot, int top)
{
if (bot < top)
{
int mid = bot + (top - bot) / 2;
merges(bot, mid);
merges(mid + 1, top);
merge(bot, mid, top);
}
}
private void merge(int bot, int mid, int top)
{
for …Run Code Online (Sandbox Code Playgroud)