
נכתב במקור על ידי
ענברושמאמוש
התרגיל:
כתוב פעולה המקבלת מערך הבנוי מרצפים ומספר שלם k. על הפעולה לבצע הזזה מעגלית ימינה של המערך k פעמים. אם לאחר k הזזות נקטע רצף של מספרים זהים, יש להמשיך ולבצע את ההזזה עד לסיום הרצף.
לדוגמא: עבור המערך 7,7,12,45,45,45,6,6,8 ו- k=4
יתקבל תחילה המערך: 45,6,6,8,7,7,12,45,45
אך מכיוון שאין לקטוע רצף המערך שיתקבל הוא: 45,45,45,6,6,8,7,7,12
תודה לעוזרים 
מצטער שזה לקח הרבה זמן. מקווה שיעזור לך(אם לא הבנת משהו תגידי) הערות באנגלית מטעמי נוחות בלבד.(לא הבנת, תשאלי)
קוד PHP:
static void Move(int[] arr, int k) { int temp = 0; // the value of the last item // We need to store each time the last item. for(int i = 0; i < k; i++) { // move the items around for "k" times. temp = arr[arr.length-1]; // storig the last item data at temp; arr[arr.length-1] = 0; // giving the last item a value of 0 - for debugging. for(int j = arr.length-1; j > 0; j--) { // moving the items around arr[j] = arr[j-1]; } arr[0] = temp; // setting the first item with the value of the last one } // while the sequence is not valie(as you mentioned "45,6,6,8,7,7,12,45,45") // we will keep going until validity " 45,45,45,6,6,8,7,7,12" while(arr[arr.length-1] == arr[0]) { temp = arr[arr.length-1]; arr[arr.length-1] = 0; for(int j = arr.length-1; j > 0; j--) { arr[j] = arr[j-1]; } arr[0] = temp; } }
לגרסה קריאה יותר - http://pastebin.com/WBkNT3g8