数据结构---递归用法
来源:互联网 发布:山治 知乎 编辑:程序博客网 时间:2024/06/02 02:33
#include<iostream>using namespace std;struct Node{ Node(int data) :_data(data) ,_next(NULL) {} int _data; Node* _next;};//void PrintfListFromTail2Head(Node* pHead)//1.逆序打印单链表//{// if(pHead)// {// PrintfListFromTail2Head(pHead->_next);// cout<<pHead->_data<<"";// }//}////void FunTest1()//1.逆序打印单链表//{// Node node1(1),node2(2),node3(3),node4(4);// node1._next=&node2;// node2._next=&node3;// node3._next=&node4;// PrintfListFromTail2Head(&node1);//}//void DestoryList(Node*& pHead)//2.销毁链表中的结点//{// if(pHead)// {// DestoryList(pHead->_next);// delete pHead;// pHead=NULL;// }//}//void FunTest2()//2.销毁链表中的结点//{// Node* p1=new Node(1);// Node* p2=new Node(2);// Node* p3=new Node(3);// Node* p4=new Node(4);// p1->_next=p2;// p2->_next=p3;// p3->_next=p4;// DestoryList(p1);//}//Node* Find(Node* pHead,int data)//3.查找值为data的结点//{// if(pHead)// {// Node* res=Find(pHead->_next,data);// if(res)// {// return res;// }// else// {// if(pHead->_data==data)// return pHead;// }// }// return NULL;//}////Node* FunTest3()//3.查找值为data的结点//{// Node node1(1),node2(2),node3(3),node4(4);// node1._next=&node2;// node2._next=&node3;// node3._next=&node4;// return Find(&node1,2);//}//int BinarySearch(int* array,int left,int right,int data)//4.二分查找//{// if(left<right)// {// int mid=left+((right-left)>>1);// if(array[mid]==data)// return mid;// else if(array[mid]>data)// return BinarySearch(array,left,mid-1,data);// else// return BinarySearch(array,mid+1,right,data);// }// return -1;//}////void FunTest4()//4.二分查找//{// int array[]={1,2,3,4,5,6,7,8,9,10};// int result=BinarySearch(array,0,9,2);// cout<<result<<endl;//}//void PrintArray(int* array,int size)//5.逆序打印数组//{// if(size)// {// cout<<array[size-1]<<"";// PrintArray(array,size-1);// }//}////void FunTest5()//5.逆序打印数组//{// int array[]={1,2,3,4,5,6,7,8,9};// PrintArray(array,9);//}//bool IsPalindereme(char* str,size_t size)//6.判断是否为回文字符串//{// if(size<=1)// return true;// if(str[0]!=str[size-1])// return false;// return IsPalindereme(str+1,size-2);//}////void FunTest6()//6.判断是否为回文字符串//{// char* str="abbaba";// cout<<IsPalindereme(str,6)<<endl;//}void Perm(int* array,int size,int N)//7.全排列{ size_t idx; if(size==N) { for(idx=0;idx<N;++idx) cout<<array[idx]<<""; cout<<endl; } else { for(idx=N;idx<size;++idx) { std::swap(array[idx],array[N]); Perm(array,size,N+1); std::swap(array[idx],array[N]); } }}void FunTest7()//7.全排列{ int array[]={1,2,3,4}; Perm(array,4,0);//全排列 cout<<endl; Perm(array,4,2);//前两位不排 cout<<endl; Perm(array,4,4);//4位都不动(不排)}int main(){ //FunTest1();//1.逆序打印单链表 //FunTest2();//2.销毁链表中的结点 //cout<<FunTest3()->_data<<endl;//3.查找值为data的结点 //FunTest4();4.二分查找 //FunTest5();//5.逆序打印数组 //FunTest6();//6.判断是否为回文字符串 FunTest7();//7.全排列 return 0;}
0 0
- 数据结构---递归用法
- 数据结构---递归
- 数据结构 - 递归
- 数据结构:递归
- 数据结构-递归
- 数据结构-递归
- 【数据结构】递归
- 【数据结构】递归
- 数据结构 递归
- 《数据结构》递归算法
- 数据结构:递归 算法分析
- 《数据结构》递归算法
- 《数据结构》递归算法
- JAVA数据结构之递归
- 数据结构.非递归
- JAVA数据结构之递归
- 《数据结构》递归算法
- 数据结构 递归讲解
- python学习之代码规范
- JS作用域、作用域链与闭包详解
- Android框架之路——RecyclerView的使用
- NYOJ12 喷水装置(二)
- 学习淘淘商城第二十三课(添加商品的实现)
- 数据结构---递归用法
- [Android]通过JNI实现卸载自身App后台发送Http请求~
- 第一章
- VS2013或15 MVC提示“当前上下文中不存在ViewBag”的解决方案
- es6箭头函数
- Hadoop安装配置详解
- java多态
- 单例模式的七种写法
- 【Python】用C语言编写Python模块