Guest User

Guy.pwn

a guest
Oct 1st, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.31 KB | None | 0 0
  1. #define DIALOG_ARRAY (1)
  2. #define DIALOG_EDIT (2)
  3. new Array[10];
  4. public OnPlayerCommandText(playerid, cmdtext[])
  5. {
  6.     if(!strcmp(cmdtext, "/editarray"))
  7.     {
  8.         new string[1024];
  9.         for(new i = 0; i < sizeof(Array); i++) format(string, sizeof(string), "%sArray[%d] = %d\n", string, i, Array[i]);
  10.         ShowPlayerDialog(playerid, DIALOG_ARRAY, DIALOG_STYLE_LIST, "Edit the array as you wish:", string, "Edit", "Cancel");
  11.         return 1;
  12.     }
  13.     if(!strcmp(cmdtext, "/sortarray"))
  14.     {
  15.         quickSort(Array, 0, sizeof(Array) - 1);
  16.         return 1;
  17.     }
  18.     return 0;
  19. }
  20. //
  21. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  22. {
  23.     switch(dialogid)
  24.     {
  25.         case DIALOG_ARRAY:
  26.         {
  27.             if(response)
  28.             {
  29.                 new string[10];
  30.                 format(string, sizeof(string), "Array[%d] edition:", listitem);
  31.                 SetPVarInt(playerid, "cell", listitem);
  32.                 ShowPlayerDialog(playerid, DIALOG_EDIT, DIALOG_STYLE_INPUT, string, "Type in a number.", "Okay", "Cancel");
  33.             }
  34.             else SendClientMessage(playerid, -1, "You have decided to abort the array edition.");
  35.         }
  36.         case DIALOG_EDIT:
  37.         {
  38.             if(response)
  39.             {
  40.                 Array[GetPVarInt(playerid, "cell")] = strval(inputtext);
  41.                 SendClientMessage(playerid, -1, "You have edited a number in the array, this is the refreshed one.");
  42.                 new string[1024];
  43.                 for(new i = 0; i < sizeof(Array); i++) format(string, sizeof(string), "%sArray[%d] = %d\n", string, i, Array[i]);
  44.                 ShowPlayerDialog(playerid, DIALOG_ARRAY, DIALOG_STYLE_LIST, "Edit the array as you wish:", string, "Edit", "Cancel");
  45.             }
  46.             else
  47.             {
  48.                 DeletePVar(playerid, "cell");
  49.                 SendClientMessage(playerid, -1, "You have aborted the array edition.");
  50.             }
  51.         }
  52.     }
  53.     return 0;
  54. }
  55. //
  56. stock quickSort(array[], left, right)
  57. {
  58.     new
  59.         tempLeft = left,
  60.         tempRight = right,
  61.         pivot = array[(left + right) / 2],
  62.         tempVar
  63.     ;
  64.     while(tempLeft <= tempRight)
  65.     {
  66.         while(array[tempLeft] < pivot) tempLeft++;
  67.         while(array[tempRight] > pivot) tempRight--;
  68.  
  69.         if(tempLeft <= tempRight)
  70.         {
  71.             tempVar = array[tempLeft], array[tempLeft] = array[tempRight], array[tempRight] = tempVar;
  72.             tempLeft++, tempRight--;
  73.         }
  74.     }
  75.     if(left < tempRight) quickSort(array, left, tempRight);
  76.     if(tempLeft < right) quickSort(array, tempLeft, right);
  77. }
  78. //
Advertisement
Add Comment
Please, Sign In to add comment