1, sequential storage of linear table analysis
Efficiency analysis
Problem
Two seqlist of the same length, inserting and deleting
Whether the average time elapsed is the same.
2, Programming experiment seqlist Efficiency analysis SeqList.h
is the following code correct? Why.
Two times free heap space
is the following code correct? Why.
Two inserts, and two object destructor frees up the same heap space
Analysis
For a class of container types, you can consider disabling copy construction and assignment operations.
3, code optimization
List.h SeqList.h
List.h
#ifndef LIST_H #define LIST_H #include "Object.h" namespace dtlib { template <typename t> class list : public object { protected: list (const list& e); //Direct declaration for the protection of members can be List& operator= (const list& e); public: list () {} virtual bool insert (const t & e) = 0; virtual bool insert (int i,const t& e) = 0; virtual bool remove (int i) = 0; virtual bool set (int i,const t& e) = 0; virtual bool get (int i,t& e) const = 0; virtual int length () const = 0; virtual void clear () = 0; }; } #endif // LIST_H
SeqList.h
Increase
BOOL Insert (const t& e)
{
return insert (M_LENGTH,E);
}
Main.cpp
#include <iostream> #include "DynamicList.h" using namespace std; using namespace dtlib; int main () { dynamiclist<int> l (5); for (Int i=0;i<l.capacity (); i++) { l.insert (i); } for (Int i=0;i<l.length (); i++) { &NBSP;&NB