منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
linked list - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغات البرمجة الاخرى (http://vb4arb.com/vb/forumdisplay.php?fid=4)
+--- قسم : قسم لغة Java (http://vb4arb.com/vb/forumdisplay.php?fid=17)
+---- قسم : قسم اسئلة Java (http://vb4arb.com/vb/forumdisplay.php?fid=22)
+---- الموضوع : linked list (/showthread.php?tid=12094)



linked list - bestwishes - 18-04-15

السلام عليكم
عندي سؤال اتمنى القى احد يشرح لي حتى احله بشكل صحيح

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]