Startpunkten
This commit is contained in:
76
AVL_tree/header.hpp
Normal file
76
AVL_tree/header.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
//##################################################################
|
||||
// PROGRAMMERINGSUPPGIFT 2
|
||||
// DATASTRUKTURER OCH ALGORITMER
|
||||
// AVL TRÄD
|
||||
//==================================================================
|
||||
// HEADER.HPP
|
||||
// Filen innehåller definition som används i programmet
|
||||
// Christian Ohlsson
|
||||
// Karlstad 980927
|
||||
//==================================================================
|
||||
#ifndef _header_
|
||||
#define _header_
|
||||
|
||||
#include <iostream.h>
|
||||
#include <fstream.h>
|
||||
#include <iomanip.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <conio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
const int FALSE = 0; //boolsk variabel
|
||||
const int TRUE = !FALSE; //boolsk variabel
|
||||
const int BUFFERSIZE = 100; //för säker inmatning
|
||||
const int FILENAMESIZE = 8; //för MS-DOS 6.0
|
||||
const int NAMESIZE = 20; //antal tecken som kan matas in som namn
|
||||
const int NUMBERSIZE = 20; //antal tecken som kan matas in som nummer
|
||||
const int ENTER = 13; //ASCII kod för enter
|
||||
const int BACKSPACE = 8; //ASCII kod för backspace
|
||||
|
||||
//typedef int bool; //definierar boolsk variabel
|
||||
typedef char nameType[NAMESIZE]; //sätter nametypen till char
|
||||
typedef char numberType[NUMBERSIZE]; //sätter numberTypen till char
|
||||
struct treeNode; //förvarnar datorn om en struct
|
||||
typedef treeNode* ptrType; //ger en pekartype till en struct
|
||||
struct treeNode{ //en nod i trädet
|
||||
|
||||
nameType name;
|
||||
numberType number;
|
||||
ptrType left;
|
||||
ptrType right;
|
||||
int height;
|
||||
treeNode(nameType oneName,numberType number,
|
||||
ptrType left, ptrType right,
|
||||
int height);
|
||||
};
|
||||
|
||||
class treeClass
|
||||
{
|
||||
public:
|
||||
treeClass();
|
||||
~treeClass(){};
|
||||
ptrType node;
|
||||
ptrType seek(ptrType node, nameType value);
|
||||
bool isEmpty();
|
||||
void destroyTree(ptrType &node);
|
||||
void setHeight(ptrType &node);
|
||||
void rotation(ptrType &node);
|
||||
void inOrder(ptrType treeNode);
|
||||
void del(ptrType &node, nameType oneName);
|
||||
void insert(ptrType &node,nameType oneName,numberType number, int height);
|
||||
void save(ptrType node, fstream &fil);
|
||||
private:
|
||||
int balance(ptrType &node);
|
||||
int maxHeight(ptrType &node);
|
||||
int size;
|
||||
void singleLeft(ptrType &node);
|
||||
void singleRight(ptrType &node);
|
||||
void doubleRL(ptrType &node);
|
||||
void doubleLR(ptrType &node);
|
||||
void delLeft(ptrType &node, nameType oneName, numberType oneNumber);
|
||||
void delRoot(ptrType &node);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user