我想知道在c ++中快速编写图形的实现.我需要数据结构易于操作和使用图形算法(例如BFS,DFS,Kruskal,Dijkstra ......).我需要这个实现的算法Olympiad,所以更容易编写数据结构更好.
你能建议这样的DS(主要结构或类别以及将在其中的内容).我知道邻接列表和邻接矩阵是主要的可能性,但我的意思是更详细的代码示例.
例如,上次我必须为DFS实现图形时,我想到了这个DS:
struct Edge {
int start;
int end;
struct Edge* nextEdge;
}
Run Code Online (Sandbox Code Playgroud)
然后使用一个大小为n的数组,在第i个位置包含表示从第i个节点开始的边的边缘列表(struct Edge).
但是当在这个图上尝试DFS时,我不得不用大约10个while循环编写50行代码.
有什么'好'的实施?
在我必须在C89标准中执行的项目中,我必须检查文件是否存在.我该怎么做呢?
我想过要用
FILE *file;
if ((file = fopen(fname, "r")) == NULL)
{
printf("file doesn't exists");
}
return 0;
Run Code Online (Sandbox Code Playgroud)
但我认为可能有更多的情况,然后文件不存在,将执行fopen == NULL.
我该怎么做呢?我宁愿不使用包含而不是.
我试图从PHP(Zend Framework)代码连接到aspx Web服务.我需要通过帖子发送几个参数到页面(电子邮件,密码).我曾尝试使用Zend_Http_Client,并执行此操作:
$client = new Zend_Http_Client('https://thesiteurl.asmx/Login');
$client->setMethod(Zend_Http_Client::POST);
$client->setAuth($username, $password);
$client->setParameterPost(array('email' => 'email', 'password' => 'password'));
$response = $client->request();
$this->view->response = $response;
Run Code Online (Sandbox Code Playgroud)
$username, $password我用来登录Web服务的用户名和密码在哪里(它有一个弹出窗口,要求我输入用户名和密码).
这段代码给了我未经授权的页面.所以我问我在哪里使用网站用户名和密码错了?我该如何使用它们?
编辑:Auth是auth-basic.
EDIT2:
我和网络服务的老板谈过他说一切都是UTF-8这是一个问题,不是默认的吗?如果不是我怎么做?
我使用下一个代码从一个文件中读取所有元素,其中包含有效的句柄hFile,以及我使用它的大小GetFileSize(hFile, NULL).
_TCHAR* text = (_TCHAR*)malloc(sizeOfFile * sizeof(_TCHAR));
DWORD numRead = 0;
BOOL didntFail = ReadFile(hFile, text, sizeOfFile, &numRead, NULL);
Run Code Online (Sandbox Code Playgroud)
操作之后text是日语中的一些奇怪的东西,而不是文件的内容.
我做错了什么?
编辑:我理解这是编码问题,但是如何将文本转换为LPCWSTR以使用WriteConsoleOutputCharacter之类的东西
我正在使用UITable实现泡泡聊天,我希望每次有人发布消息时向下滚动表.是否可以使表格视图向下滚动?我怎么做?
写完下面的代码后:
#include <iostream>
using namespace std;
typedef struct Node {
int value;
Node(int index) {
value = index;
}
} Node;
int main() {
Node* arr[10];
for(int i = 0; i < 10; i++) {
arr[i] = &Node(i);
}
for(int i = 0; i < 10; i++)
cout << arr[i]->value << endl;
}
Run Code Online (Sandbox Code Playgroud)
我看到代码只打印了9个,而不是从0到9的所有数字.在调试代码后,我看到每个i的arr [i]的地址是相同的,并且Node(i)只为arr [i]释放了一次空间,之后唯一value = index没有释放任何其他空间的东西.为什么?
我使用Wampserver 2.1与mysql版本5.1.53.
这个查询:
SELECT * FROM `contents` WHERE 1
Run Code Online (Sandbox Code Playgroud)
运行,而这个查询
IF 1
SELECT * FROM `contents` WHERE 1
Run Code Online (Sandbox Code Playgroud)
不,我得到错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF 1 SELECT * FROM内容WHERE 1' at line 1
我已经查了几次"IF"语法并找不到问题.为什么会这样?
在这些代码失败的哪些行中(意思是:不做它们应该做的事情),为什么?
int main(void) {
char student[64] = "some guy";
char* teacher;
/* line1 */ strcpy(teacher, student);
/* line2 */ teacher=student;
/* line3 */ strcpy(student, "Alber Einstein");
/* line4 */ student = teacher;
}
Run Code Online (Sandbox Code Playgroud) 为什么这个代码有问题(在visual studio 2010中)?
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;
int main() {
map<string,int> map;
map<string,int>::iterator iter = map.begin();
}
Run Code Online (Sandbox Code Playgroud)
它只是告诉我迭代器定义中存在一个问题(类模板"std :: iterator"的参数列表缺失),但是我看到了这样写的样本.