[面试] 递归 反向输出链表 ,定义一个求字符串长度的函数, 反向输出字符串. 不能再函数内部定义变量.
2013-01-25 21:20
676 查看
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <vector> #include <stack> #include <deque> #include <queue> #include <bitset> #include <list> #include <map> #include <set> #include <iterator> #include <algorithm> #include <functional> #include <utility> #include <sstream> #include <climits> #include <cassert> #define BUG puts("here!!!"); using namespace std; struct Node { int value; Node* next; }; Node* creat() { Node* head = new Node(); assert(head != NULL); head->value = 1; Node* p = head; for(int i = 2; i < 10; i++) { p->next = new Node(); p = p->next; p->value = i; } return head; } void reverse(Node* head) { Node* p = head; if(head == NULL) return; if(p->next) { reverse(p->next); } cout << p->value << ' '; } int main() { Node* head = creat(); reverse(head); cout << endl; return 0; }求字符串长度
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <vector> #include <stack> #include <deque> #include <queue> #include <bitset> #include <list> #include <map> #include <set> #include <iterator> #include <algorithm> #include <functional> #include <utility> #include <sstream> #include <climits> #include <cassert> #define BUG puts("here!!!"); using namespace std; int getLen(char* p) { if(*p == '\0') return 0; return getLen(p+1) + 1; } int main() { char str[] = "abcdefg"; cout << getLen(str) << endl; return 0; }
相关文章推荐
- [面试] 递归 反向输出链表 ,定义一个求字符串长度的函数, 反向输出字符串. 不能再函数内部定义变量.
- 递归:从尾到头输出链表& 从尾到头输出一个字符串 & 定义一个函数求字符串的长度,要求该函数体内不能声明任何变量
- 定义一个函数求字符串的长度,要求该函数体内不能声明任何变量
- 定义一个函数求字符串的长度,要求该函数体内不能声明任何变量
- 定义一个函数求字符串的长度,要求该函数体内不能声明任何变量
- 定义一个函数求字符串的长度,要求该函数体内不能声明任何变量
- 【C语言】实现一个函数求字符串长度(不能创建第三方变量)
- 用递归的思想写编写一个函数reverse_string(char * string)实现字符串反向输出和反向排列
- //4. 编写一个函数reverse_string(char * string)(递归实现) //实现:将参数字符串中的字符反向排列。 //要求:不能使用C函数库中的字符串操作函数。
- 编写一个函数reverse_string(char * string)(递归实现)实现:将参数字符串中的字符反向排列。要求:不能使用C函数库中的字符串操作函数。
- 编写一个函数reverse_string(char * string)(递归实现) 实现:将参数字符串中的字符反向排列。 要求:不能使用C函数库中 的字符串操作函数。
- 写一个函数,输入int型,返回整数逆序后的字符串。如:输入123,返回“321”。 要求必须用递归,不能用全局变量,输入必须是一个参数,必须返回字符串
- 【C语言】编写一个函数reverse_string(char * string)(递归实现),将参数字符串中的字符反向排列,不能使用C函数库中的字符串操作函数。
- C语言---递归反向输出任意长度的字符串
- 递归实现将参数字符串中的字符反向排列,要求不能使用C函数库中的字符串操作函数
- 写一函数,求一个字符串的长度。在main函数中输入字符串,并输出其长度。(指针)
- C语言 编写一个函数reverse_string(char * string) 实现:将参数字符串中的字符反向排列。 要求:不能使用C函数库中的字符串操作函数。
- 利用函数递归逆序输出一个字符串
- 用字符指针变量指向一个字符串,然后输出字符及其长度
- 假如现在有一堆长度大于3小于9的电话号码,用座机呼叫,如果出现这样的号码【123和12345】那么12345将永远不会被拨出,因为拨到123的时候电话已经呼出了,试写一个函数输出所有不能被呼出的电话号码(java实现)