Implement unlimited Classification through iteration

Source: Internet
Author: User

Speaking of the infinitus classification, I believe many people know what it is and have done it before. I also believe that the most widely used method is to implement recursion.

Recently, I also want to create a menu with unlimited classification, but I don't want to use recursion. So I need to implement it in other ways, that is, iteration.

First, I need to define an entity model. Here is an example of an infinite province/city:

      ID { ;   PID { ;   Name { ; ; }              Level { ; ; }          }

Then write the method. here we need to take advantage of the features of stack first-in-first-out:

          List<Loaction> Soft(List<Loaction> data, = <Loaction> tree =  List<Loaction> level =  (task.Count >  flag =  ( i = ; i < data.Count; i++ l = (l.PID ====++--= (! (task.Count > =--

Finally, prepare the data-> call-> output:

          Main( data =  List<Loaction> Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  Loaction() { ID = , PID = , Name =  tree = Soft(data,  ( t  sb =  ( i = ; i < t.Level; i++  

Then the effect is as follows:

That's what it looks like ..... (END)

Related Article

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.