1、写一函数int fun(char *p)判断一字符串是否为回文,是返回1,不是返回0,出错返回-1.(例如:字符串”123454321”就是回文字符串)
int fun(char *p)
{
if(p==NULL)
return -1;
else
{
int length = 0;
int i = 0;
int judge = 1;
length = strlen(p);
for(i=0; i<length/2; i++)
{
if(p[i]!=p[length-1-i])
judge = 0;
break;
}
if(judge == 0)
return 0;
else
return 1;
}
}
2、假设现有一个单向的链表,但是只知道只有一个指向该节点的指针p,并且假设这个节点不是尾节点,试编程实现删除此节点。
节点结构:struct node
{
int data;
struct node *p_next;
};
p=p->p_next;
free(p);
3、Write a function string reverse string word By word(string input) that reverse a string word by word.
For instance:
“The house is blue” –> “blue is house The”
“Zed is dead” –>”dead is Zed”
“All-in-one” –> “one-in-All”
在不增加任何辅助数组空间的情况下,完成function
字符串中每个单词(子串)的逆序
思路
原字符串: The house is blue
先翻转整个字符串-> eulb si esuoh ehT
再翻转单个单词。