java - List items ordering problem -
i have list of items , set of users. users can re-order list items. each user has own view list, can arrange items in own way. 1 item can placed in different locations in list different users. i've track item location users in list item. please give suggestion implement this. size of list not constant. i'm using java. intension have show list every user in ordering format. please masters give me suggestion.
you can keep ordered list of, well, order retrieve items master list:
list<foo> items = new arraylist<foo>(); // add stuff items (say, 6 things) map<string,list<integer>> userorders = new hashmap<string,list<integer>>(); userorders.put("a", arrays.aslist(0,1,2,3,4,5)); // add user a's order userorders.put("b", arrays.aslist(5,4,3,2,1,0)); // add user b's order // display usera: for(integer : userorders.get("a")){ show(items.get(i)); // show usera's i-th item }
here i'm using map
hold orders. depending on application might use other scheme retrieve user's custom ordering, principle same: if user can have custom order, should store ordering somewhere, , iterate through list of things based on ordering (as shown above).
also take care type of list
you're using, calling get
random access on linkedlist
substantially more costly on arraylist
.
Comments
Post a Comment