大家好我试图从vector中删除void指针,程序在删除时崩溃.非常感谢你!
template <class T> class tArray_t : public vpArr_t {
virtual ~tArray_t() {
for (vector<void*>::iterator it = array.begin() ; it != array.end(); )
{
vector<void*>::iterator nextElement = it+1;
delete *it; // here is the crash
it = nextElement;
}
Run Code Online (Sandbox Code Playgroud)
};
我是C++的新手,我正在编写这个程序,当我运行它时应该发出哔哔声.我到处搜索,我觉得我的代码是正确的,但我听不到哔哔声.(我的发言人也在)请帮忙!
#include<iostream>
using namespace std;
int main()
{
//please beep
cout << "\a";
cout << "other text" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 如果以下循环结构处于上限分析中,它是否仍然计算为 O(n^2)?我很困惑,因为内部循环依赖于外部循环,并且每次外部迭代时,内部 for 循环都会少循环一次。除了 O(n) 是什么之外,时间复杂度函数是否会是“n!.n+C”(其中 C 是常数)?我假设n!因为内循环。
for(int i=n;i>0;i--)
{
for(int j=i;j>=1;j--)
{
count++;
}
}
Run Code Online (Sandbox Code Playgroud) 我已将代码隔离在两个文件中,如下所示.这是头文件graph.h
//graph.h
#ifdef GRAPH_H
#define GRAPH_H
#include <vector>
#include <fstream>
#include "kernel_def.h"
using namespace std;
typedef vector<bool> Array;
typedef vector<Array> TwoDArray;
class baseGraph {
private:
int nodes; /*Number of nodes.*/
vector<feature_vector *> vec; /*vector of feature nector.*/
public:
baseGraph(int nodes);
/*set-get functions*/
int getNodes();
void setNodes(int nodes);
const feature_vector *getVec(int pos);
int setVec(int pos, feature_vector *fVec);
/*Input edges from file and set up in corresponding representation.*/
virtual void setGraph(ifstream &ipf) = 0;
/*Utility functions*/
virtual void printGraph() = 0; …
Run Code Online (Sandbox Code Playgroud) 如果我注释行插入(s,10),下面的程序编译正常;
#include <iostream>
#include <iterator>
#include <set>
using namespace std;
template <class T>
void insert(std::set<T>& _s, const T& t) {
typename std::set<T>::const_iterator i = _s.insert(t);
}
int main() {
std::set<int> s;
// insert<int>(s, 10); // line No: 14
}
Run Code Online (Sandbox Code Playgroud)
但如果我取消注释第14行,那么我得到的错误是:
set.cpp:9:54: error: conversion from ‘std::pair<std::_Rb_tree_const_iterator<int>, bool>’ to non-scalar type ‘std::set::const_iterator’ requested
问题是:现代数学的一个着名证明是Georg Cantor的证明,即有理数的集合是可以计算的.证明通过使用有理数字的显式枚举来工作,如下图所示.
1/1 1/2 1/3 1/4 1/5 ...
2/1 2/2 2/3 2/4
3/1 3/2 3/3
4/1 4/2
5/1
Run Code Online (Sandbox Code Playgroud)
在上图中,第一项是1/1,第二项是1/2,第三项是2/1,第四项是3/1,第五项是2/2,依此类推.
您将编写一个程序,该程序将读取1到107范围内的数字列表,并将为每个数字打印Cantor枚举中的相应术语,如下所示.最后一个号码后面不应出现空行.输入列表每行包含一个数字,并将以文件结尾终止.输入文件中不会出现超过30个数字.
我写的代码是:
stepOver = do [left num den dir]
count <- getLine
let left = count' -1
if left == 0
then putStrLn [num den]
let newleft = left -1
case (stepOver num) of
1 -> if dir == up
stepOver = [newleft 1 (den + 1) down]
stepOver = [newleft 2 (den - 1) down]
case (stepOver den) of
1 …
Run Code Online (Sandbox Code Playgroud) 我想创建一个while循环来连接xs
列表中的字符串,直到找到一个空字符串,但似乎我们既没有机会增加Int也没有创建while循环.
所以这看起来像是Haskell的伪代码,但我怎样才能真正实现我的解决方案呢?
prt :: String -> [String] -> Int -> String
prt str xs x = do
while((xs !! (x)) /= "")
str = str ++ (xs !! (x++))
Run Code Online (Sandbox Code Playgroud) 我是Haskell中的新手,运行在Haskell下面的代码,第4章是RealWorld Haskell Book并获得
<interactive>:48:1: parse error on input ‘./’
Run Code Online (Sandbox Code Playgroud)
这是我在WinGHCi 1.0.6上执行的
Prelude> :load Interact
[1 of 1] Compiling Main ( Interact.hs, interpreted )
Ok, modules loaded: Main.
*Main> --make Interact
*Main> :load Interact
[1 of 1] Compiling Main ( Interact.hs, interpreted )
Ok, modules loaded: Main.
*Main> ./Interact "infrank.txt" "outfrank.txt"
*<interactive>:48:1: parse error on input ‘./’*
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?因为我试图谷歌周围没有希望
以下是RealWorld Haskell第4章的代码
-- file: ch04/Interact.hs
-- Save this in a source file, e.g. Interact.hs
import System.Environment (getArgs)
interactWith function inputFile outputFile = do …
Run Code Online (Sandbox Code Playgroud)