项目作者: iAmDorra

项目描述 :
Chaining items by ids
高级语言: C#
项目地址: git://github.com/iAmDorra/ChainingItems.git
创建时间: 2018-03-06T22:40:09Z
项目社区:https://github.com/iAmDorra/ChainingItems

开源协议:

下载


Chaining items

Imagine that we have a collection of 20000 items.
An item has those properties :

  • id
  • previousItemId
  • followingItemId

The goal is to get out chains from the collection.

Let’s get a scenario :

  1. Given those items :
  2. { id = 1, previousItemId = 2, followingItemId = 3 },
  3. { id = 2, previousItemId = 4, followingItemId = 1 },
  4. { id = 3, previousItemId = NULL, followingItemId = NULL },
  5. { id = 4, previousItemId = NULL, followingItemId = 2 },
  6. { id = 5, previousItemId = 8, followingItemId = NULL },
  7. { id = 6, previousItemId = NULL, followingItemId = 7 },
  8. { id = 7, previousItemId = NULL, followingItemId = NULL },
  9. { id = 8, previousItemId = 9, followingItemId = NULL },
  10. { id = 9, previousItemId = NULL, followingItemId = 8 },
  11. { id = 10, previousItemId = NULL, followingItemId = NULL },
  12. { id = 11, previousItemId = NULL, followingItemId = NULL }
  13. When I run the chaining algo
  14. Then I should get those chains
  15. {4, 2, 1, 3},
  16. {9, 8, 5},
  17. {6, 7},
  18. {10},
  19. {11}

Enjoy :)