Linear table 1

1、Linear table (LIST)Forms of expression
  • Consisting of zero or more data elements.aggregate
  • Data elements in positionIn orderPermutation
  • The number of data elements isfiniteA
  • Data elementtypeMustidentical
 
2、Properties of linear tables
  • a0For the first element of a linear table, there is only one successor.
  • an-1 For the last element of a linear table, there is only one precursor.
  • Except a0And an-1 The other elements are precursors and post drives.
  • Direct support for itemized access and sequential access
 
3、Some common operations of linear tables
  • Create a linear table
  • Destroy linear list
  • Inserting elements into linear tables
  • Deleting elements from the linear table
  • Gets the value of a location element in a linear table.
  • Setting the value of an element in a linear table.
  • Get the length of a linear table
  • Clear linear list
4、The performance of linear tables in programs: a special kind ofdata type
     Create a class (that is, a new data type).
Class template
 1 template <typename T>
 2 class list: public Object
 3 {
 4 public:
 5     virtual bool insert(int i, const T& e)=0;
 6     virtual bool remove(int i)=0;
 7     virtual bool set(int i,const T& e)=0;
 8     virtual bool get(int i,T& e) const=0;
 9     virtual int length() const =0;
10     virtual void clear()=0;
11 }

 

 
 Code implementation:
Because it is implemented by class templates, there is no need for CPP files.
 
List.h
 
 1 #ifndef LIST_H
 2 #define LIST_H
 3 #include"object.h"
 4  5 namespace DTLib
 6 {
 7 template <typename T>
 8  9 class List: public Object
10 {
11 public:
12     virtual bool insert(int i, const T& e)=0;
13     virtual bool remove(int i)=0;
14     virtual bool set(int i,const T& e)=0;
15     virtual bool get(int i,T& e) const=0;
16     virtual int length() const =0;
17     virtual void clear()=0;
18 };
19 }
20 #endif // LIST_H

 

 
 
ListJust one.abstract class,Used to beinherit
 
main.cpp 
 
#include <iostream>
#include "list.h"using namespace std;
using namespace DTLib;
​
​
int main(int argc, char *argv[])
{
  List<int>* l=NULL;
  return 0;
}
​
 

 

 
5、Summary
  • A linear table is ordered by data elements.Finite set
  • The data elements in the linear table must beOf the same type
  • The linear table can be used to describe queuing problems.
  • The linear form is a special data type in the program.
  • The linear table is represented in C++.Abstract class
 

Leave a Reply

Your email address will not be published. Required fields are marked *