Data structures and algorithms analyze tables, stacks, and queues

Source: Internet
Author: User
Tags abstract definition

A table is an abstract definition of arraylist,linkedlist,stack,queue. I understand it as an ordered single data store.

Use of the Remove method with the LinkedList class

Simulates a scene, iterates over a linkedlist, and deletes the values stored in them as even numbers.

    • Method One: Use subscript I for A For loop, if found to be an even number, and then remove (i) to delete. The time complexity of this method is O (N2), because the complexity of the outer traversal is n, the memory is going to get (i) and remove (i) their complexity is n.
    • Method Two: Using the enhanced for loop, an exception is generated: The enhanced for loop uses iterator during the loop, but instead of using remove in iterator, the List.remove method is not recognized by iterator. Therefore, the following requirements: The enhanced for loop process, the data cannot be deleted.
    • Method Three: Use iterator. Iterator.hashnext, Iterator.next, Iterator.remove, because iterator at remove, has been positioned to delete the list element position, so the complexity of the delete operation is O (1), The time complexity of the entire implementation is O (N).
Listiterator

Listiterator added Hasprevious,previous,add,set method on the basis of iterator (Hasnext,next,remove).

Data structures and algorithms analyze tables, stacks, and queues

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.