使用链接列表创建字典数据结构.
typedef struct _dictionary_entry_t
{
const char* key;
const char* value;
struct dictionary_entry_t *next;
struct dictionary_entry_t *prev;
} dictionary_entry_t;
typedef struct _dictionary_t
{
dictionary_entry_t *head;
dictionary_entry_t *curr;
int size;
} dictionary_t;
Run Code Online (Sandbox Code Playgroud)
使用函数将字典条目添加到链表.
int dictionary_add(dictionary_t *d, const char *key, const char *value)
{
if (d->curr == NULL) //then list is empty
{
d->head = malloc(sizeof(dictionary_entry_t));
d->head->key = key; //set first dictionary entry key
d->head->value = value; //set first dictionary entry value
d->head->next = NULL;
//d->curr = d->head;
}
else
{
d->curr …Run Code Online (Sandbox Code Playgroud) 令 G = (V, E) 为节点 v_1, v_2,..., v_n 的有向图。如果 G 具有以下性质,则称 G 是有序图。
给出一个有效的算法,该算法采用有序图 G 并返回从 v_1 开始到 v_n 结束的最长路径的长度。
如果你想看到漂亮的乳胶版本:在这里
我的尝试:
动态规划。Opt(i) = max {Opt(j)} + 1. 对于所有 j 这样的 j 可以从 i 到达。
也许有更好的方法来做到这一点?我认为即使有记忆,我的算法仍然是指数级的。(这只是我在网上找到的旧中期审查)
我有以下课程:
template <class... T>
class thing {};
template <class T>
class container {
public:
container() {
std::cout << "normal constructor" << std::endl;
}
};
Run Code Online (Sandbox Code Playgroud)
我可以用container<int>这种方式为构造函数编写一个完整的特化:
template <>
container<int>::container() {
std::cout << "int constructor" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
我希望能够为其定义类似的构造函数container<thing<T>>.我认为我试图写的是模板函数的部分特化(这是非法的.)这是我正在尝试的:
template <class T>
container<thing<T>>::container() {
}
Run Code Online (Sandbox Code Playgroud)
这不编译.
我不完全确定解决这个问题的正确方法是什么,以及模板类函数的重载和特化之间的界限越来越模糊.这可以简单地解决,还是需要type_traits(std::enable_if)?我怎么解决这个问题?
c++ templates partial-specialization template-specialization c++14
我正在经历一些旧的中期学习.(没有给出解决方案)
我遇到过这个我坚持的问题
- 对于某个正整数l,设n = 2 l - 1.假设有人声称拥有一个不同的ℓ比特串的数组A [1 .. n]; 因此,A中没有出现一个ℓ比特的字符串.进一步假设我们可以访问A的唯一方法是调用函数FetchBit(i,j),它返回字符串A [i]的第 j 位O(1)时间.
描述一种算法,仅使用对FetchBit的O(n)调用来查找A中缺少的字符串.
我唯一能想到的是遍历每个字符串,将其转换为基数10,对它们进行排序,然后查看缺少哪个值.但那肯定不是O(n)
证明它不是功课... http://web.engr.illinois.edu/~jeffe/teaching/algorithms/hwex/f12/midterm1.pdf
我的导师给了我以下功能.所以不要怪我暧昧哈哈
void step_step_step(char *first, char *second, char *third)
{
if (third[3] == second[2] + 8 && second[2] == first[1] + 8)
printf("8: Illinois\n");
else
printf("8: ERROR\n");
}
Run Code Online (Sandbox Code Playgroud)
我尝试以这种方式调用该函数:
char *p8_1 = (char*) malloc(sizeof(char)*11);
char *p8_2 = (char*) malloc(sizeof(char)*11);
char *p8_3 = (char*) malloc(sizeof(char)*11);
p8_1[9] = 'u';
p8_2[2] = p8_1[9];
p8_2[10] = p8_1[9];
p8_3[3] = p8_2[10];
step_step_step(p8_1, p8_2, p8_3);
Run Code Online (Sandbox Code Playgroud)
它会导致打印错误.我在这做错了什么?我不明白为什么当我的其他解决方案没有时,这不起作用:
p8_2[2] = p8_1[1] + 8;
p8_3[3] = p8_2[2] + 8;
step_step_step(p8_1, p8_2, p8_3);
Run Code Online (Sandbox Code Playgroud) 我有点卡在这里。我知道可以递归地找到特定的斐波那契数,如下所示:
int fib (int n)
{
if (n <= 1)
return n;
else
return fib(n-1) + fib(n-2);
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以迭代地调用该函数 n 次来找到斐波那契数的总和
int sum = 0;
for (int i = 0; i < n; i++)
{
sum += fib(i);
}
Run Code Online (Sandbox Code Playgroud)
但我很难想出一个递归函数来求和。我认为它与原始的斐波那契函数没有太大不同。(这是一项旨在提高我编写 ocaml 语法的能力的作业,而不是编写递归函数)
当我在浏览器中加载它时,不会显示任何内容.如果我注释掉最后一行它工作正常.我认为,如果最后一行导致某种类型的错误,它将被报告,而不是没有发生任何事情.
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
echo "hello"
$xml = simplexml_load_file(dirname(__FILE__).'/svn_log.xml')
?>
Run Code Online (Sandbox Code Playgroud)