![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构和算法
Charlies.
这个作者很懒,什么都没留下…
展开
-
线性表--链表
链表的使用及简单功能template typedef struct Node{ T Data; struct Node *Next;} List;List L,*PtrL;//求表长int Length(List *PtrL){ List*p=PtrL;//指向表头 int j=0; while(p)//到表尾 {原创 2015-08-10 14:35:34 · 380 阅读 · 0 评论 -
各种排序算法更新
折半插入排序public static void insertHaltSort(int[] array) { int tem,j,i,l,h,mid;//i指的是无序区的第一个元素,j指的是有序区的最后一个元素 for (i = 1; i < array.length; i++) { tem=array[i]; j=i-1;l=0;h=j; while(l&l...原创 2019-06-09 08:44:00 · 170 阅读 · 0 评论 -
Collection和Map的遍历
Collection的遍历 Collection collection=new ArrayList<>(); collection.add('a'); collection.add('b'); //foreach增强遍历 for (Object object : collection) { System.out.println(object);...原创 2019-06-19 08:36:55 · 267 阅读 · 0 评论 -
使用链栈判断输入的表达式中的括号是否配对
#include #include using namespace std;typedef char ElemType;typedef struct linknode{ ElemType data; struct linknode *next;} LiStack;bool Match(char exp[],int n);//判断表达式中括号是否配对void Init原创 2016-03-27 09:58:30 · 4011 阅读 · 0 评论 -
栈的链式存储结构及其基本运算的实现
#include #include using namespace std;typedef char ElemType;typedef struct linknode{ ElemType data; struct linknode *next;} LiStack;void InitStack(LiStack *L);//初始化栈void DestroyStack(L原创 2016-03-27 09:40:07 · 905 阅读 · 0 评论 -
线性表--顺序表中将所有小小于0的整数移到大于0的前面
将所有小小于0的元素移到大于0的前面#include #include using namespace std;#define MaxSize 10typedef int ElemType;typedef struct{ ElemType data[MaxSize]; int length;}SqList;void InitiList(SqList *&L,E原创 2016-03-23 11:30:50 · 7107 阅读 · 3 评论 -
设计删除顺序表中【x,y】中的所有元素算法
线性表L采用顺序存储结构,删除元素在[x,y]之间的所有元素。代码如下:#include #include using namespace std;#define MaxSize 10typedef char ElemType;typedef struct{ ElemType data[MaxSize]; int length;}SqList;void In原创 2016-03-23 10:53:43 · 9000 阅读 · 1 评论 -
环形队列中实现队列的基本运算
代码如下:#include #include #define MaxSize 10using namespace std;typedef char ElemType;typedef struct{ ElemType data[MaxSize]; int front,rear;} SqQueue;void InitQueue(SqQueue *q)//初始化队列原创 2016-04-01 20:29:22 · 4213 阅读 · 0 评论 -
队列的顺序存储结构及其基本运算的实现
队列是一种受限的线性表,其限制为仅在表的一段进行插入,在表的另一端进行删除。队尾为rear,队首为front,队列的 基本特征先进先出。 #include #include #define MaxSize 10using namespace std;typedef char ElemType;typedef struct{ ElemType data[MaxSize]原创 2016-04-01 12:08:37 · 1310 阅读 · 0 评论 -
判断一个字符串是否为回文
判断一个字符串是否为回文代码如下:#include using namespace std;bool judge(string );int main(){ string str; cin >> str; if(judge(str)) cout<<"YES"<<endl; else cout<<"NO"; r原创 2016-03-07 17:03:28 · 901 阅读 · 0 评论 -
一个正整数各位之和
计算一个正整数各位之和代码如下:#include using namespace std;int main(){ int x; int sum = 0; cin>>x; while(x / 10 !=0) { sum += x %10; x = x/10; }原创 2016-03-07 17:01:35 · 776 阅读 · 0 评论 -
线性表的顺序存储
#include//malloc函数头文件//ElementType 表示数据类型 MAXSIZE表示数组最大容量typedef struct{ ElementType Data[MAXSIZE]; int Last;} List;//初始化(建立空的顺序表)List *MakeEmpty(){ List *PtrL; PtrL=(List *)mal原创 2015-08-08 09:55:16 · 508 阅读 · 0 评论 -
顺序栈
栈的顺序实现方法templateclass stack{public: void Clear(); //清空栈 bool Push(const T item);//栈的压入操作 bool Pop(T & item);//读取栈顶元素的值并删除 bool Top(T & item);//读取栈顶的元素色值不删除 bool isEmpty();//原创 2015-08-10 15:39:06 · 367 阅读 · 0 评论 -
判断一个数是不是水仙花数
问题:水仙花数是指一个 n 位的整数,它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153)思路:将给定的整数数的各个位上的数拆分,用ArrayList数组保存;然后根据(例如:1^3 + 5^3 + 3^3 = 153)条件判断。下面代码为求得区间[n,m]的水仙花数的个数 //拆分给定的数的各个位,保存到ArrayList数组中,...原创 2019-08-09 10:16:31 · 2916 阅读 · 0 评论