bintreeu指针.h

author author     2023-03-23     207

关键词:

binarno stablo header pokazivac
  1. typedef int labeltype;
  2.  
  3. struct element{
  4. labeltype label;
  5. struct element * left,* right;
  6. };
  7.  
  8. typedef struct element * bnode;
  9. typedef struct element * btree;
  10.  
  11. bool testExistB(bnode n, btree T){
  12. if (n) return true;
  13. return false;
  14. }
  15.  
  16. bnode LeftChildB(bnode n, btree T){
  17. return n->left;
  18. }
  19.  
  20. bnode RightChildB(bnode n, btree T){
  21. return n->right;
  22. }
  23.  
  24. bnode ParentB(bnode n, btree T){
  25. static bnode tekuci = T;
  26. if (tekuci->left==n || tekuci->right==n) return tekuci;
  27. if (tekuci->left) ParentB(LeftChildB(tekuci, T), T);
  28. if (tekuci->right) ParentB(RightChildB(tekuci, T), T);
  29. }
  30.  
  31. labeltype LabelB(bnode n, btree T){
  32. return n->label;
  33. }
  34.  
  35. void ChangeLabelB(labeltype x, bnode n, btree T){
  36. n->label = x;
  37. }
  38.  
  39. bnode RootB(btree T){
  40. return T;
  41. }
  42.  
  43. void CreateLeftB(labeltype x, bnode n, btree T){
  44. if (n->left) {
  45. cout << "Nije moguce stvoriti cvor, cvor je vec zauzet ";
  46. return;
  47. }
  48. bnode novi = new element;
  49. novi->label = x;
  50. novi->left = NULL;
  51. novi->right = NULL;
  52. n->left = novi;
  53. }
  54.  
  55. void CreateRightB(labeltype x, bnode n, btree T){
  56. if (n->right) {
  57. cout << "Nije moguce stvoriti cvor, cvor je vec zauzet ";
  58. return;
  59. }
  60. bnode novi = new element;
  61. novi->label = x;
  62. novi->left = NULL;
  63. novi->right = NULL;
  64. n->right = novi;
  65. }
  66.  
  67. void DeleteB(bnode n, btree T){
  68. if (n->left) DeleteB(LeftChildB(n, T), T);
  69. if (n->right) DeleteB(RightChildB(n, T), T);
  70. delete n;
  71.  
  72. }
  73.  
  74.  
  75. btree InitB(labeltype x, btree T){
  76. T = new element;
  77. T->label = x;
  78. T->left = NULL;
  79. T->right = NULL;
  80. return T;
  81. }

指针的好处

#include<pthread.h>#include<stdio.h>#include<sys/time.h>#include<string.h>#include<stdlib.h>#defineMAX10pthread_tthread[2];pthread_mutex_tmut;intnumber=0,i;structparamete 查看详情

c指针汇总

C指针使用拾零一、指针申请空间1.创建多个指针*p、*q、*r,但只为其中一个指针*p申请空间,其他指针(*q、*r)指向此指针(*p)申请的空间,则这三个指针中最后一次修改的即为最后空间存储的。 例如:#include<stdio.h>#i... 查看详情

7,指针用法,计算器代码

#define_STDC_WANT_LIB_EXT1_1#include<stdio.h>#include<string.h>#include<ctype.h>#include<stdlib.h>#include<stdbool.h>#include<math.h>#defineBUF_LEN256intmain(void){ 查看详情

二维数组和数组指针的关系

  昨天既然写了一些关于数组指针的话题,那么今天就写一些关于数组指针的话题吧!  数组指针:这样读数组的指针,即指向数组的指针,就是数组指针,其本质就是一个指针  比如:int(*a)[3];就是一个数组指针,运用... 查看详情

这个指针返回安全吗?

】这个指针返回安全吗?【英文标题】:Isthispointerreturnsafe?【发布时间】:2019-06-1212:11:31【问题描述】:几天前,我想找到atoi的安全替代方案,并找到以下代码作为对thisSO问题的回复:#include<assert.h>#include<ctype.h>#include&... 查看详情

2.指针

1.指针也是一种变量(从内存的角度看,就是分配四个字节的内存),占有内存空间,用来保存内存地址。2.指针变量和它指向的内存块是两个不同的概念。例:拷贝字符串#include<stdlib.h>#include<string.h>#include<stdio.h>#pragma... 查看详情

野指针产生的原因

...include<stdio.h>#include<stdlib.h>#include<string.h>//野指针产生的原因//指针变量和它所指向的内存空间变量是两个不同的概念//释放了指针所指的内存空间但是指针变量本身没有重置成null//造成释放的时候通过if(p1!=NULL)//避免... 查看详情

线程之间是不是共享指针? [复制]

】线程之间是不是共享指针?[复制]【英文标题】:Arepointerssharedbetweenthreads?[duplicate]线程之间是否共享指针?[复制]【发布时间】:2013-11-2816:32:55【问题描述】:#include<pthread.h>#include<stdio.h>#include<stdlib.h>#include<unis... 查看详情

5.二级指针

 一.二级指针的输入模型#include<stdlib.h>#include<string.h>#include<stdio.h>#pragmawarning(disable:4996)intprintArray(char**pArray,intnum){if(pArray==NULL){return-1;}inti=0;for(i=0;i<nu 查看详情

第二十七课再论智能指针(上)(代码片段)

思考:  使用智能指针替换单链表LinkLIst中的原生指针是否可行?将LinkList.h中的Node指针全部改成智能指针:1#ifndefLINKLIST_H2#defineLINKLIST_H34#include"List.h"5#include"Exception.h"6#include"SmartPointer.h"78namespaceDTLib91011template<ty 查看详情

字符串与指针(代码片段)

...gt;voidmain()charstring[]="Ilovechina";printf("%s",string);(2)用字符指针指向一个字符串例:可以不用定义字符数组,而定义一个字符指针,用字符指针指向字符串中的字符。#include<stdafx.h>#include<stdio.h>voidmain()char*string="Ilovechina";pr... 查看详情

指针地址和结构体中的数组(代码片段)

看看指针和结构体中的数组怎么用的,很基础的,搞清楚一点好。#include<stdio.h>#include<stdlib.h>#include<stdint.h>#include<stdbool.h>#include<stddef.h>#include<unistd.h>#include<f 查看详情

函数接受结构指针和返回结构指针有奇怪的行为?(代码片段)

...代码我调用了insert函数,它传递一个指向struct(table)的指针,insert函数接收一个指针并执行一些操作并再次返回它。但是运行代码会导致分段错误。当我尝试使用传递的指针访问struct数组中的值。#include<stdio.h>#include<stdli... 查看详情

指针和数组关系的浅析

  关于指针和数组之间的关系,估计有人还是对于数组与指针地址的关系有些模糊,对于这点,我今天对这一点做一个小小的总结好了;  我们已经知道指针和数组的用法差不多,但是指针的地址和指针指向的地址是不一样... 查看详情

结构体指针

  今天我们来说一说结构体指针,真如同前面讲过的结构体也是一种数据类型,既然是数据类型就可以通过它来定义指针变量,代码如下:  1#define_CRT_SECURE_NO_WARNINGS//一个warning,阻止对不安全函数的警告2#include<stdio.h>3#... 查看详情

指针值传递指针的指针指针的引用无法返回临时变量地址

#include<stdio.h>#include<stdlib.h>#include<string.h>voidGetMemory(char*p) //char*p=str,p=str(值传递,跟str无关,内存分配失败) p=(char*)malloc(100);voidGetMemory1(char**p) //char**p=&str,p指 查看详情

函数内部的指针行为

】函数内部的指针行为【英文标题】:pointerbehaviourinsidefunction【发布时间】:2017-10-2316:50:35【问题描述】:我不明白函数在作为参数传递时如何改变指针的状态。例如,在这段代码中-#include<stdio.h>#include<string.h>#include<... 查看详情

获取指针数据的大小

】获取指针数据的大小【英文标题】:GettingthesizeofthedataofaPointer【发布时间】:2010-12-0622:41:19【问题描述】:我尝试了以下代码以查看如何:#include<stdio.h>#include<stdlib.h>#include<string.h>intmain()char*test_char_ptr="Thisisjustates... 查看详情