Review Table ADT 7 points

Source: Internet
Author: User

1. For all operations of a table, arrays can be used, and arrays are statically allocated, but the vector class of the internal storage array allows to increase the size of the array by one times when needed.

2. It is precisely because of the implementation of the array that printlist is executed in linear time, and findkth even through constant time. The worst is the insertion and deletion, if the position is not good, for example, in position No. 0 to insert the entire array will need to move all the elements back to O (N). To avoid the linear overhead of insertions and deletions, we started using a technique called a list of lists (Linked).

3. The list consists of a number of nodes that are connected in memory, and each node has a link to the table element and the node of the element's successor. This is called next chain, and naturally the next chain of the last unit points to null.

4.STL is the full name of "Standard Template Library", the Chinese name is to do the "Standards Templates gallery." The table ADT is in it.

5. An array is a pointer to memory variable, memory block can be allocated by new[], but also must be released with delete[], the size of the memory block cannot be changed.

6. Combine a new node containing x with the nodes pointed to by P and P.prev, and the pointer assignment can be written as follows.

*newNode=new Node(x,p->prev,p);p->prev->next=newNode;p->prev=neweNode;

But it can also be merged:

*newNode=new Node(x,p->prev,p);p->prev=p->prev->next=newNode;

It can then be further merged:

p->prev=p->prev->next=new Node(x,p->prev,p);

So you can write insert operations like this:

& x){    *p=itr.current;    theSize++;    return iterator(p->prev=p->prev->next=new Node(x,p->prev,p));}   

7. Similarly, for a two-way list of delete operations, this would be the case:

p->prev->next=p->next;p->next->prev=p->prev;delete p;

The Insert function after the modification.

iterator insert(iterator itr,constObject & x){    itr.assertIsValid();    if(itr.theList!=this)        throw IteratorMismatchException();    Node *p=itr.current;    theSize++;    returnthis,p->prev=p-prev->next=new Node(x,p->prev,p));}

Review Table ADT 7 points

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.