尝试使用模板制作B inary S earch T ree(简称BST).
当我尝试创建BST的新实例时,出现意外错误.我希望解决方案不涉及指针,因为我希望将它们保持在最低限度.
现在我有:
template <typename Type>
class BST { // The binary search tree containing nodes
private:
BSTNode<Type> *root; // Has reference to root node
public:
BST ();
bool add (int, Type);
};
Run Code Online (Sandbox Code Playgroud)
和节点类型:
编辑:当我删除代码以解除对文本的阻碍时,我忘记了构造函数,现在它被添加了
template <typename Type>
class BSTNode { // Binary Search Tree nodes
private:
int key; // we search by key, no matter what type of data we have
Type data;
BSTNode *left;
BSTNode *right;
public:
BSTNode (int, Type&);
bool …Run Code Online (Sandbox Code Playgroud) 我有一个任务,我需要创建自己的(简单)通用链表:
public class Node<T> {
private int key;
private T data;
private Node<T> nextNode;
}
Run Code Online (Sandbox Code Playgroud)
但是我需要用哈希表来实现一个字典.我想制作一个包含Node的列表.如果发生冲突(两个类型的对象分散到同一节点,我只需链接它们 - 链接列表).
我必须自己实现这个,没有外部帮助(已经实现了列表或者什么)
我多么想这样做:
public class GenericDictionary<T> implements GenericDictionary_interface<T> {
private int capacity;
private Node<T> [] slots;
public GenericDictionary () {
this.capacity = 31;
slots = new Node<T>[capacity]; // the array I need which I disperse to
}
}
Run Code Online (Sandbox Code Playgroud)
然而,这并非完全可能.我确实尝试过阅读这个主题,尝试在这里搜索...但我根本没有得到它.
我唯一的要求是......不要对变量/方法名称保持懒惰,请让它们易于理解.
要澄清:由于来自Eclipse的消息,我甚至无法编译.第一个代码段:input并且inputBuffer无法识别.第二个代码片段,Eclipse希望我将交换机"Compliance and JRE切换到1.7"
我是资源尝试的新手,我不太了解语法或我做错了什么.这是我的代码
try {
FileReader input = new FileReader(this.fileName);
BufferedReader inputBuffer = new BufferedReader (input);
String line;
while ((line = inputBuffer.readLine()) != null) {
String[] inputData = line.split(",");
Node<Integer> newNode = new Node<Integer>(Integer.parseInt(inputData[0]),
Integer.parseInt(inputData[1]));
this.hashMap.add(newNode);
}
//inputBuffer.close();
//input.close();
}catch (NumberFormatException nfe){
System.out.println(
"Repository could not load data due to NumberFormatException: " + nfe);
}catch (FileNotFoundException fnfe) {
System.out.println("File not found, error: " + fnfe);
}finally {
inputBuffer.close();
input.close();
}
Run Code Online (Sandbox Code Playgroud)
finally块不起作用,所以我想试试
try (FileReader input …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写协议缓冲区(gRPC)映射。
我有一个类结构如下
public abstract class A;
public class B extends A;
public class C extends A;
public class Source {
A a1;
A a2;
}
Run Code Online (Sandbox Code Playgroud)
我有一个原始文件,上面写着:
message Target {
oneOf {
B b1 = 1;
C c1 = 2;
}
oneOf {
B b2 = 3;
C c2 = 4;
}
}
Run Code Online (Sandbox Code Playgroud)
AKA,proto 有两个 VALID 字段,但有四个真实字段,source 只有两个字段。而且类型也很复杂。Mapstruct 将无法根据类型签名理解我想要的内容,我需要使用一些限定符来帮助它。
我还设置了它,以便任何未映射的目标属性都是错误。
这让我陷入了尴尬的境地。据我了解,mapstruct 只有源条件。只是存在检查,我不能将其设为“无论我想要什么检查”。
在理想的世界里,我会简单地写:
message Target {
oneOf {
B b1 = 1;
C c1 = 2;
}
oneOf {
B b2 …Run Code Online (Sandbox Code Playgroud) 我根本无法理解这里发生了什么.这个问题对我的作业很重要(学习编程所以我是初学者......我的英语也不是那么好,对不起).
我正在尝试读取一个字符串......它可以是一个数字或一定数量的命令.
我只是给出一个很小的例子,说明我正在尝试做什么以及出了什么问题.
def validate():
choice = str(input(">>> "))
if (choice == "exit"):
return 0 # should exit validate
else:
try:
aux = int(choice) # Tries converting to integer
except:
print("Insert integer or exit")
validate() # If it can't convert, prompts me to try again through
# recursivity
else:
return aux
rezult = validate()
print (rezult)
Run Code Online (Sandbox Code Playgroud)
问题是这个小脚本返回完全随机的东西.
如果"退出",则返回"无".
如果第一次输入正确,则返回正确的数字.
如果第一个输入是"错误"而第二个输入是正确的,那么它再次是"无",我根本无法理解出现了什么问题......为什么它不想工作或我应该做什么(或者).
我有一个家庭作业,用汇编语言为8086系列处理器制作一个简单的程序,读取并打印软盘上占用的总空间.
现在我有几个问题.我知道我必须使用中断,但我不知道哪一个以及它是如何工作的,我尝试了诺顿指南,但我找不到我想要的东西.另一个问题是我没有软盘或者有一台软盘的机器......我完全没办法测试这个程序.
换句话说,我被卡住了
编辑:
另外我如何乘以3个单词?Ax*Cx*Dx?因为Word*Word =双字......我不知道如何将双字与Word相乘.
在一门课程中,老师给了我们一些代码(在粉笔板上),但是他手写的很糟糕,而且我不能做出一些部分.管道和叉子也是新的,所以没有帮助.
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
void main () {
int a[] = {1,2,3,4}, f[2]; // ok so we initialize an array and a "pipe folder" (pipefd in manual) ?
pipe (f); // not 100% sure what this does ?
if (fork () == 0) { // if child
close (f[0]); // close pipe read-end
a[0] += a[1];
write (f[1], &a[0], sizeof (int)) // fixed
close (f[1]); // close pipe write-end
exit(0); // closes child and sends …Run Code Online (Sandbox Code Playgroud) 我想使用QLineEdit编写QString,然后使用QPushButton,我想将一个项目(一个字符串)添加到listView
这是我得到的:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
model = new QStringListModel(this);
QStringList list;
list << "Some Item";
model->setStringList(list);
ui->listView->setModel(model);
ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
void MainWindow::on_pushButton_3_clicked()
{
//add
int row = model->rowCount(); // model = new QStringListModel
model->insertRow(row);
QModelIndex index = model->index(row);
ui->listView->setCurrentIndex(index);
ui->listView->edit(index); // instead of edit, I'd like to ... add a QString
}
Run Code Online (Sandbox Code Playgroud)
问题是我不想编辑(这是我自己设法做的全部).我现在想要在CurrentIndex中添加一个项目,并将该项目作为文本字段lineEdit.如何访问该字段?是lineEdit->text()吗?以及如何将其添加到列表视图?
我根本不知道如何在列表中添加任何内容.我发现错误编辑,谷歌到目前为止没有帮助.我希望Stack Overflow能够并且愿意.
编辑:我已经决定尝试这个,但它似乎不是最好的解决方案
void MainWindow::on_pushButton_3_clicked()
{
//add
QStringList list;
list = model->stringList();
list.append(ui->lineEdit->text());
model->setStringList(list);
}
Run Code Online (Sandbox Code Playgroud)
但这似乎是一种奇怪的做事方式.由于某种原因,似乎还包括换行符.
这段代码好像坏了,但我不明白为什么:
System.out.println(line);
// prints: Some Name;1|IN03PLF;IN02SDI;IN03MAP;IN02SDA;IN01ARC
String args[] = line.split("|");
String candidatArgs[] = args[0].split(";");
String inscrieriString[] = args[1].split(";");
System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(candidatArgs);
System.out.println("[0]:" + candidatArgs[0]);
System.out.println("[1]:" + candidatArgs[1]);
// prints: S
// [Ljava.lang.String;@4f77e2b6
// [0]:
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会这样.按我的逻辑:
String args[] = line.split("|");
[0]: Some Name;1
[1]: IN02SDI;IN03MAP;IN02SDA;IN01ARC
Run Code Online (Sandbox Code Playgroud)
代替:
[0]: S
Run Code Online (Sandbox Code Playgroud)
如果你想要更多的代码:这应该编译即使它没有做太多(删除尽可能多的不必要的代码)
主要:
有一个文件: Candidati.txt
含: Some Name;1|IN03PLF;IN02SDI;IN03MAP;IN02SDA;IN01ARC
import java.util.ArrayList;
Repository repository = new Repository ("Candidati.txt"); // file name
ArrayList<Candidat> candidati = repository.getCandidati();
System.out.println(candidati);
Run Code Online (Sandbox Code Playgroud)
知识库
import java.util.ArrayList;
public class Repository {
private String …Run Code Online (Sandbox Code Playgroud) 我正在制作一个包含姓名,电子邮件等的简单表格,但我也有一个ModifiedDate.我的想法是在插入和更新后使用触发器,并插入当前日期.因此,如果任何人对该列做任何事情(除了删除),日期应该反映出来.
然而,这不起作用.
CREATE TRIGGER ModDate
ON X
AFTER INSERT, UPDATE
AS
BEGIN
INSERT INTO X (ModifiedDate)
VALUES (GETDATE())
END
Run Code Online (Sandbox Code Playgroud)
现在我有几个不能为null的值,这似乎是尝试创建一个新行.我希望它将日期插入当前正在执行的行中,我不知道如何.如果我一次添加5行怎么办?
我是编程和C++的初学者.我之前使用过模板,但是以非常有限的方式使用模板,我不知道我做错了什么:
template <typename TElement>
struct list{ // if I try list<TElement> => list is not a template
TElement data;
struct list *next;
} node_type; // also tried node_type<TElement>, other incomprehensible errors
node_type *ptr[max], *root[max], *temp[max];
Run Code Online (Sandbox Code Playgroud)
我发现错误有点难以理解:"node_type does not name a type"
我做错了什么?
我打算做什么:
我想要一个类型列表(所以我可以在几个完全不同的抽象数据类型 - ADT上使用它),所以我想最终得到这样的东西:
Activities list *ptr[max], *root[max], *temp[max]
Run Code Online (Sandbox Code Playgroud)
如果这有意义(在哪里Activities是一个类,但可以是任何其他类).
public class ExtAA extends AA {
static int iTime;
public static void main(String argv[]) {
ExtAA d = new ExtAA();
d.func(iTime);
}
public static void func(int iTime) {
System.out.println(iTime);
}
public ExtAA() { }
}
class AA {
public AA() { System.out.println("AA"); }
}
Run Code Online (Sandbox Code Playgroud)
打印:
AA
0
Run Code Online (Sandbox Code Playgroud)
我本来希望public ExtAA() { }覆盖构造函数AA,因此不会打印AA 0.有人可以解释我错在哪里,如果我想覆盖构造函数,我怎么办?
PS我的问题完全有可能是愚蠢的,但我不知道公共ExtAA()应该或可以做什么.这是一个测试,我搞砸了,我想知道实际发生了什么(是的,我确实进入调试并一步一步地进行调试,我只是不知道为什么new ExtAA使用AA而不是它自己定义的构造函数)
public class Tabel {
private static int dimension;
private ArrayList<ArrayList<Character>> tabel;
public Tabel(int dimension) {
Tabel.dimension = dimension;
for (int i=0;i<Tabel.dimension*Tabel.dimension;i++) {
tabel.add(new ArrayList<Character>());
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试调试(eclipse ide)时,我会遇到很多奇怪的"错误",或者至少我会遇到一些我认为意想不到的错误.
private static int不会出现在debug的"variables"部分.
我得到一个NullPointerException上tabel.add(...),但是当我观看了调试,它进入for一次,在表中不添加任何东西,因为当我点击"下一步",而不是跳转到花括号它跳出功能.
如果我发表评论,.add那就是问题(我认为).我的语法错了吗?或者我应该发布更多代码?