hufflist.cpp

来自「经典c++程序的实现」· C++ 代码 · 共 42 行

CPP
42
字号
// Copy of llist.c for huffman tree lists (change element type)

#include <stdio.h>
#include <iostream.h>
#include <assert.h>

#include "..\include\book.h"

// Include the following line for general list tests
// typedef int ELEM;

// Include the following lines for Huffman code test
#include "..\include\lettfreq.h"
typedef LettFreq* BELEM;
#include "..\include\bintree.h"
#include "..\include\hufftree.h"
typedef HuffTree* ELEM;

#include "..\include\linkf.h"

// This creates space for the freelist variable
link* link::freelist = NULL;

void* link::operator new(size_t) { // Overload new operator
  if (freelist == NULL) return ::new link;  // Create new space
  link* temp = freelist;           // Otherwise, get from freelist
  freelist = freelist->next;
  return temp;                     // Return the link node
}

void link::operator delete(void* ptr) { // Overload delete operator
  ((link*)ptr)->next = freelist;        // Put on freelist
  freelist = (link*)ptr;
}

#include "..\include\llist.h"

// Include the member functions for list: the ELEM type is unique to
// Huffman coding, so this is included here.
#include "..\include\llist.x"
#include "..\include\llist2.x"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?