# Implement example

&#x20;        จากตัวอย่างด้านล่าง ตัวอย่างนี้เป็นตัวอย่างการจัดเรียงค่าในอาร์เรย์โดยเรียงจากค่าน้อยไปค่ามากโดยใช้หลักการเรียงแบบ Selection sorting&#x20;

![Algorithm of Selection sorting](/files/-MS1i0WEGAl0Dn49StL3)

```cpp
#include <iostream> 
using namespace std; 

void printarr(int arr[],int n) {        
  for (int i=0;i<n;i++){
    cout<<arr[i]<<" ";
  }

}
void selectionSort(int a[], int n) {
   int i, j, min, temp;
   for (i = 0; i < n - 1; i++) {
      min = i; //initial min value
      for (j = i + 1; j < n; j++) 
      if (a[j] < a[min]) // replace curent min value
      min = j;
      temp = a[i];
      a[i] = a[min];
      a[min] = temp;
   }
}


int main() 
{ int allnumber[] = {4,11,76,4,88,3,11};
  int arrsize = *(&allnumber + 1) - allnumber; //find array length 
  selectionSort(allnumber, arrsize);
  printarr(allnumber, arrsize);
    return 0; 
} 
```

ผลที่ได้จากการรัน

![](/files/-MS1iUcy3xVYZQOb97-e)

อ้างอิง selection sorting: [wikipedia.org](https://th.wikipedia.org/wiki/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%87%E0%B8%A5%E0%B8%B3%E0%B8%94%E0%B8%B1%E0%B8%9A%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B9%80%E0%B8%A5%E0%B8%B7%E0%B8%AD%E0%B8%81)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/c-c++-for-embedded-programming/c-programming-techniques/array-and-properties-of-an-array/implement-example.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
