数据结构
Luke@
这个作者很懒,什么都没留下…
展开
-
设计在链式存储结构上合并排序的算法。
void mergelklist(lklist *ha,lklist *hb,lklist *&hc){ lklist *s=hc=0; while(ha!=0 && hb!=0) { if(ha->data<hb->data) { if(s==0) hc=s=ha; else{ s->...原创 2019-10-18 13:57:41 · 2535 阅读 · 2 评论 -
链表:设计在单链表中删除值相同的多余结点的算法。
typedef struct node { int data; struct node *next;}lklist;void delredundant(lklist *&head){ lklist *p,*q,*s; for(p=head;p!=0;p=p->next) { for(q=p->next,s=q;q!=0;) ...原创 2019-10-14 17:58:42 · 3310 阅读 · 0 评论 -
设计在链式结构上实现简单选择排序算法。
void simpleselectsorlklist(lklist *&head){ lklist *p,*q,*s; int min,t; if(head==0 ||head->next==0) return; for(q=head; q!=0;q=q->next) { min=q->data; s=q; for(p=q->next;...原创 2019-10-14 17:42:07 · 2164 阅读 · 0 评论 -
设计在链式结构上实现直接插入排序算法。
void straightinsertsort(lklist *&head){ lklist *s,*p,*q; int t; if (head==0||head->next==0) return; else{ for(q=head,p=head->next;p!=0;p=q->next) { for(s=head;s!=q->next...原创 2019-10-14 17:38:30 · 10368 阅读 · 20 评论 -
链表:编写一个函数void delet(LNode *L, int n, int m)。函数功能:删除递增有序链表中值大于n且小于m的所有元素。
#include <stdio.h>#include <stdlib.h>#define N 5typedef struct list{ int data; struct list *next;}LNode;LNode *creatlist(int *a){ LNode *h,*p,*q; int i; h...原创 2019-10-08 16:52:10 · 716 阅读 · 0 评论 -
链表:编写一个函数int fun(LNode *h,int x)。函数功能:查找链表是否存在一个值为x的结点,若存在则删除并返回1,否则返回0。
#include <stdio.h>#include <stdlib.h>#define N 8typedef struct list{ int data; struct list *next;}LNode;LNode *creatlist(int *a){ LNode *h,*p,*q; int i; h=p=(...原创 2019-10-08 16:45:53 · 548 阅读 · 0 评论 -
链表:编写一个函数void insert(LNode *h,int x)。函数功能:在有序的单链表中插入一个值为x的结点。
#include <stdio.h>#include <stdlib.h>#define N 5typedef struct list{ int data; struct list *next;}LNode;LNode *creatlist(int *a){ LNode *h,*p,*q; int i; h...原创 2019-10-08 16:22:52 · 3600 阅读 · 1 评论 -
链表:编写一个函数int fun(LNode *h,int x)。函数功能:统计链表中数值为x的结点的个数。
#include <stdio.h>#include <stdlib.h>#define N 5typedef struct list{ int data; struct list *next;}LNode;LNode *creatlist(int *a){ LNode *h,*p,*q; int i; h...原创 2019-10-08 16:00:49 · 1331 阅读 · 0 评论 -
链表:编写一个函数int count(LNode *h)。函数功能:统计单链表中结点的个数。
#include <stdio.h>#include <stdlib.h>#define N 5typedef struct list{ int data; struct list *next;}LNode;LNode *creatlist(int *a){ LNode *h,*p,*q; int i; h...原创 2019-10-08 15:54:33 · 3275 阅读 · 1 评论 -
链表:编写一个函数int max(LNode *h)。函数功能:返回链表中的最大值。
#include <stdio.h>#include <stdlib.h>#define N 5typedef struct list{ int data; struct list *next;}LNode;LNode *creatlist(int *a){ LNode *h,*p,*q; int i; h...原创 2019-10-08 15:48:40 · 621 阅读 · 0 评论 -
链表:编写一个函数void fun(LNode *A,LNode *B,LNode *&C)。函数功能:将两个递增有序的链表合并为一个递增有序的链表。
#include <stdio.h>#include <stdlib.h>#define N 5typedef struct list{ int data; struct list *next;}LNode;LNode *creatlist(int *a){ LNode *h,*p,*q; int i; h...原创 2019-10-08 15:39:19 · 1112 阅读 · 0 评论 -
链表:编写函数void reverse(LNode *h)。函数功能:利用原来的存储空间将链表逆置输出。
#include <stdio.h>#include <stdlib.h>#define N 5typedef struct list{ int data; struct list *next;}LNode;LNode *creatlist(int *a){ LNode *h,*p,*q; int i; h...原创 2019-10-08 15:21:59 · 691 阅读 · 0 评论 -
链表:前插法建立单链表。
#include <stdio.h>#include <stdlib.h>#define N 5typedef struct list{ int data; struct list *next;}LNode;LNode *creatlist(){ LNode *h,*p; int i,x,n; h=(LNod...原创 2019-10-08 15:15:04 · 975 阅读 · 0 评论 -
二叉树:设计在二叉排序树上查找结点X的算法。
bitree *bstsearch1(bitree *t, int key){ bitree *p=t; while(p!=0) if (p->key==key) return p; else if (p->key>key) p=p->lchild; else p=p->rchild; return 0;}原创 2019-10-16 19:33:52 · 4966 阅读 · 0 评论 -
二叉树:设计判断二叉树是否为二叉排序树的算法。
int minnum=-32768,flag=1;typedef struct node{ int key; struct node *lchild,*rchild;}bitree;void inorder(bitree *bt){ if (bt!=0) { inorder(bt->lchild); if(minnum>bt->key) fl...原创 2019-10-14 20:04:15 · 20198 阅读 · 7 评论 -
二叉树:设计判断两个二叉树是否相同的算法。
typedef struct node { int data; struct node *lchild,*rchild;} bitree;int judgebitree(bitree *bt1,bitree *bt2){ if (bt1==0 && bt2==0) return 1; else if (bt1==0 || bt2==0 ||bt1...原创 2019-10-14 20:00:30 · 10524 阅读 · 7 评论 -
二叉树:设计一个求结点x在二叉树中的双亲结点算法。
typedef struct node { int data; struct node *lchild,*rchild;} bitree;bitree *q[20]; int r=0,f=0,flag=0;void preorder(bitree *bt, char x){ if (bt!=0 && flag==0) if (bt->data==x) ...原创 2019-10-14 19:56:36 · 20574 阅读 · 12 评论 -
二叉树:编写一个函数void GetPreSeq(BiTNode *bt,int k)。函数功能:输出先序序列中第k个位置的结点的值。
#include <stdio.h>#include <malloc.h>typedef struct BiTNode { int data; //关键字项 struct BiTNode *lchild,*rchild; //左右孩子指针} BiTNode;int c=0;//全局变量 void GetPreS...原创 2019-10-08 21:24:13 · 315 阅读 · 0 评论 -
二叉树:编写一个函数int BTreeCount(BiTNode *T)。函数功能:计算二叉树结点的总数。
#include <stdio.h>#include <malloc.h>typedef struct BiTNode { int data; //关键字项 struct BiTNode *lchild,*rchild; //左右孩子指针} BiTNode;int BTree...原创 2019-10-08 21:29:42 · 2555 阅读 · 0 评论 -
二叉树:编写一个函数int LeafCount(BiTNode *T)。函数功能:计算二叉树叶子结点的总数 。
#include <stdio.h>#include <malloc.h>typedef struct BiTNode { int data; //关键字项 struct BiTNode *lchild,*rchild; //左右孩子指针} BiTNode;int LeafC...原创 2019-10-08 21:37:23 · 3253 阅读 · 0 评论 -
二叉树:编写一个函数int MaxValue(BiTNode *T)。函数功能:求树中关键字的最大值。
#include <stdio.h>#include <malloc.h>typedef struct BiTNode { int data; //关键字项 struct BiTNode *lchild,*rchild; //左右孩子指针} BiTNode;int MaxVa...原创 2019-10-08 21:41:35 · 1001 阅读 · 0 评论 -
二叉树:编写一个函数void Exchange(BiTNode *bt)。函数功能:交换树中每个结点的左孩子和右孩子。
#include <stdio.h>#include <malloc.h>typedef struct BiTNode { int data; //关键字项 struct BiTNode *lchild,*rchild; //左右孩子指针} BiTNode;void Exch...原创 2019-10-10 13:38:32 · 958 阅读 · 0 评论 -
二叉树:编写一个函数int LeafSum(BiTNode *T)。函数功能:计算二叉树叶子结点的值的总和 。
#include <stdio.h>#include <malloc.h>typedef struct BiTNode { int data; //关键字项 struct BiTNode *lchild,*rchild; //左右孩子指针} BiTNode;int sum=0...原创 2019-10-10 13:48:06 · 696 阅读 · 1 评论 -
二叉树:编写一个函数int Depth(BiTNode *T)。函数功能:计算二叉树的深度。
#include <stdio.h>#include <malloc.h>typedef struct BiTNode { int data; //关键字项 struct BiTNode *lchild,*rchild; //左右孩子指针} BiTNode;BiTNode...原创 2019-10-08 17:07:53 · 2172 阅读 · 0 评论