تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
linked list
#1
السلام عليكم
عندي سؤال اتمنى القى احد يشرح لي حتى احله بشكل صحيح

Write a program that will prompt the user to enter a number, n, of men. Fill a LinkedList with n Integer objects numbered 1, 2, …, n. (Hint: The Integer value will be equal to the man's position in the original list.)

The Collections class has an algorithm called rotate(List<?> list, int distance) which can be used to rotate a list left or right. Write the logic necessary to eliminate every other Integer beginning with the Integer in the second position. Remember that if you remove an item in the middle of the list, thre items which follow it are shifted forward in the list.

Continue eliminating integers until a single Integer is left. Print the list for each step in this process and the survivor's position.
As an example of this process, if we represent five men with a list of integers, [1,2,3,4,5], rotate the list to the left and remove the first man each time, we would see lists like this:

[1, 2, 3, 4, 5]
[3, 4, 5, 1]
[5, 1, 3]
[3, 5]
[3]
الرد }}}}
تم الشكر بواسطة:


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم