18th Lesson-Sequential Storage Linear Table Analysis __ Data structure actual combat development

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.