任何人都可以解释为什么我在下面的例子中得到分段错误?
#include <stdio.h>
#include <string.h>
int main(void) {
char *hello = "Hello World, Let me live.";
char *tokens[50];
strtok_r(hello, " ,", tokens);
int i = 0;
while(i < 5) {
printf("%s\n", tokens[i++]);
}
}
Run Code Online (Sandbox Code Playgroud) 我在stanford库中查看下面的代码:
void recursiveReverse(struct node** head_ref)
{
struct node* first;
struct node* rest;
/* empty list */
if (*head_ref == NULL)
return;
/* suppose first = {1, 2, 3}, rest = {2, 3} */
first = *head_ref;
rest = first->next;
/* List has only one node */
if (rest == NULL)
return;
/* put the first element on the end of the list */
recursiveReverse(&rest);
first->next->next = first;
/* tricky step -- see the diagram */
first->next = NULL;
/* fix …Run Code Online (Sandbox Code Playgroud) 我刚开始学习编程.我正在学习循环,但这个程序没有按预期工作.我想在$a等于时打破循环
,3这样我得到输出1 2但我得到3输出:(
for($a=0;$a<10;++$a)
{
if($a==3)
break
print"$a ";
}
Run Code Online (Sandbox Code Playgroud)
请帮忙.
当head作为参数发送给它时,以下代码可以正常工作.由于我是C的新手,我无法理解它是如何工作的.请帮帮我.
struct node *recursiveReverseLL(struct node *list)
{
struct node *revHead;
if (list == NULL || list->link == NULL)
{
return list;
}
revHead = recursiveReverseLL(list->link);
list->link->link = list;
list->link = NULL;
return revHead;
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用这些递归调用提供链接.即)如果链接为,
1 -> 2 -> 3 -> 4
Run Code Online (Sandbox Code Playgroud)
然后hw被改变为,
4 -> 3 -> 2 -> 1
Run Code Online (Sandbox Code Playgroud) typedef struct Node
{
int data;
Node *next;
Node *other;
};
Node *pHead;
Run Code Online (Sandbox Code Playgroud)
pHead是一个单链表.该next字段指向列表中的下一个元素.该other字段可以指向列表中的任何其他元素(可以是先前节点之一或前面的节点之一)或NULL.
如何编写复制链接列表及其连接的复制功能?新列表中的元素(next和other)都不应指向旧列表中的任何元素.
我会解释我的问题:
我有一个名为的数据库表country.它有两列:ID和name.
当我想要搜索'paris',但拼错字:'pares'('e'代替'i'),我不会得到任何DB结果.
我希望系统能够提出可能有助于搜索的类似单词.
因此,我正在寻找帮助编写一个脚本,该脚本从DB中提出包含类似词语的建议:paris,paredes,...等.
我有一个由数字组成的字符串,有时是字母.
示例AF-1234或345ww.
我必须得到数字部分并将其递增1.
我怎样才能做到这一点?可能与正则表达式?
我正在尝试查找并替换文件夹中的字符串.
有人可能会帮助我吗?
我的脚本如下:
#!/bin/bash
OLD="This is a"
NEW="I am a"
DPATH="/home/user/test/*.txt"
BPATH="/home/user/test/backup/foo"
[ ! -d $BPATH ] && mkdir -p $BPATH || :
for f in $DPATH
do
if [ -f $f -a -r $f ]; then
/bin/cp -f $f $BPATH
sed "s/$OLD/$NEW/g" "$f"
else
echo "Error: Cannot read $f"
fi
done
Run Code Online (Sandbox Code Playgroud)
现在这似乎找到字符串'This is a'并替换为'我是',但这仅打印到屏幕.
我需要它来替换文件本身.
谢谢
我在Adobe采访中被问到这个问题:
我们有一个整数数组,按升序排序.我们还有3个整数A,B和C.我们需要申请数组中的A*x*x + B*x + C每个元素x并返回相应的排序数组.
示例I给出了:
Input array = -1 0 1 2 3 4
A = -1, B = 2, C = -1`
Run Code Online (Sandbox Code Playgroud)
将公式应用于每个元素的-4 -1 0 -1 -4 -9
结果=所以预期结果= -9 -4 -4 -1 -1 0(已排序)
我最好的解决方案是应用配方并对其进行分类以产生O(nlogn)解决方案.我无法做得更好.
任何改进它的指导都是有帮助的.
给出两个排序的数组:A和B.阵列的大小A是La与阵列的大小B是Lb.如何找到A和B?
如果La比大得多Lb,那么交点查找算法会有什么不同吗?