⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clist.cpp

📁 eC++编译器源码
💻 CPP
字号:
#pragma clist
#include <stdio.h>
#include <cmalloc.h>
/* This file contains the declaration of class List.
------------------------------------------------------------------------*/
const unsigned int MaxLength=256;
typedef struct {
   ListElement
      Array[MaxLength];               //    the array
   unsigned int
      Length_;                        //    array value counter
} tlist;
typedef tlist *IList;

   void List::printf(const char format[]) const  //format applies per item
   {
     unsigned int i;
     i = 0;
     while (i<list->Length_) {
       ::printf(format, list->Array[i]);
       INC(i);
     };
   };

   void List::Open(unsigned int Len, ListElement InitVal)
   {
     list = malloc(sizeof(tlist));
     if (list==NULL) HALT;
     list->Length_ = Len;
     while (Len>0) {
       DEC(Len);
       list->Array[Len] = InitVal;
     };
   };

   void List::Close()
   {
     free(list);
     list = NULL;
   };

   /*
      Receive:  Original, a List object
      Return:   The object containing this function, with its
                  members as copies of those of Original, and a
                  reference to this List (for chained assignments)
   ----------------------------------------------------------------*/
   void List::Copy(const List& source)
   {
     list = malloc(sizeof(tlist));
     if (list==NULL) HALT;
     list->Array = source.list->Array;
     list->Length_ = source.list->Length_;
   };


   /***---Subscript---
      Receive: i, an index for a List element
      Return:  The value of the element in member Array with index i
   ----------------------------------------------------------------*/
   ListElement List::I(unsigned int i) const
   {
     return list->Array[i];
   };



   /***---Length---
      Return:  The length of the list (the value stored in field
                  Length_).
   ----------------------------------------------------------------*/

   unsigned int List::Length(void) const
   {
     return list->Length_;
   };


   /***---Searches---***/
   /***---search ---
      Receive:  SearchVal, a (ListElement) value
      Return:   The index of SearchVal, if it is present in
                   member Array, and -1 otherwise
   ----------------------------------------------------------------*/
   int List::Search (const ListElement& SearchVal) const
   {
     return -1;
   };


   /***---Find smallest value in a sublist ---
      Receive: First, the index of the first element to be examined
               Last, the index of the last element to be examined
               Last==0 indicates to search from First to last
      Return:  The index of the smallest value in the examined
                 elements
   ----------------------------------------------------------------*/
   unsigned int List::IndexOfMin(unsigned int First, unsigned int Last) const
   {
     return 0;
   };


   /***---Sorts---***/
   /***---Sort ---

      Return:   The List containing this function, its Array
                   member sorted into ascending order
   ----------------------------------------------------------------*/
   void List::Sort(unsigned int collate)
   {
    unsigned int n, i, max;
    ListElement j;
    n = 0;
    for ( ;; ) {
      if (n >= list->Length_) break;
      i = n+1;  max = n;
      for ( ;; ) {
        if (i >= list->Length_) break;
        if (collate == 0) {
          if (list->Array[i] < list->Array[max]) max = i;
        } else if (list->Array[i] > list->Array[max]) max = i;
        i = i+1;
      }; //loop
      if (max != n) {
        j = list->Array[n];  list->Array[n] = list->Array[max];  list->Array[max] = j;
      };
      n = n+1;
    }; //loop
   };

  //used to read input; the return value equals one if a value was read
  //formats are the same as for printf
  int List::scanf(const char format[])
  {
     unsigned int i;
     i = 0;
     while (i<list->Length_) {
       if (::scanf(format, list->Array[i])!=1) return i;
       INC(i);
     };
     return i;
  };

⌨️ 快捷键说明

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