Skip to content

Commit

Permalink
style: format cpp code using clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Aug 13, 2022
1 parent 06b44c5 commit e350ace
Show file tree
Hide file tree
Showing 1,452 changed files with 5,620 additions and 7,947 deletions.
8 changes: 4 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
Expand Down Expand Up @@ -56,7 +56,7 @@ CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
Expand Down
16 changes: 5 additions & 11 deletions basic/sorting/BubbleSort/BubbleSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@

using namespace std;


void bubbleSort(vector<int>& arr)
{
void bubbleSort(vector<int>& arr) {
int n = arr.size();
for (int i = 0; i < n - 1; ++i)
{
for (int i = 0; i < n - 1; ++i) {
bool change = false;
for (int j = 0; j < n - i - 1; ++j)
{
if (arr[j] > arr[j + 1])
{
for (int j = 0; j < n - i - 1; ++j) {
if (arr[j] > arr[j + 1]) {
swap(arr[j], arr[j + 1]);
change = true;
}
Expand All @@ -22,8 +17,7 @@ void bubbleSort(vector<int>& arr)
}
}

int main()
{
int main() {
vector<int> arr = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
bubbleSort(arr);
for (int v : arr) cout << v << " ";
Expand Down
16 changes: 5 additions & 11 deletions basic/sorting/BubbleSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,12 @@ func main() {

using namespace std;


void bubbleSort(vector<int>& arr)
{
void bubbleSort(vector<int>& arr) {
int n = arr.size();
for (int i = 0; i < n - 1; ++i)
{
for (int i = 0; i < n - 1; ++i) {
bool change = false;
for (int j = 0; j < n - i - 1; ++j)
{
if (arr[j] > arr[j + 1])
{
for (int j = 0; j < n - i - 1; ++j) {
if (arr[j] > arr[j + 1]) {
swap(arr[j], arr[j + 1]);
change = true;
}
Expand All @@ -123,8 +118,7 @@ void bubbleSort(vector<int>& arr)
}
}

int main()
{
int main() {
vector<int> arr = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
bubbleSort(arr);
for (int v : arr) cout << v << " ";
Expand Down
18 changes: 6 additions & 12 deletions basic/sorting/InsertionSort/InsertionSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@

using namespace std;

void printvec(const vector<int> &vec, const string &strbegin = "", const string &strend = "")
{
void printvec(const vector<int>& vec, const string& strbegin = "", const string& strend = "") {
cout << strbegin << endl;
for (auto val : vec)
{
for (auto val : vec) {
cout << val << "\t";
}

cout << endl;
cout << strend << endl;
}

void insertsort(vector<int> &vec)
{
for (int i = 1; i < vec.size(); i++)
{
void insertsort(vector<int>& vec) {
for (int i = 1; i < vec.size(); i++) {
int j = i - 1;
int num = vec[i];
for (; j >= 0 && vec[j] > num; j--)
{
for (; j >= 0 && vec[j] > num; j--) {
vec[j + 1] = vec[j];
}

Expand All @@ -32,8 +27,7 @@ void insertsort(vector<int> &vec)
return;
}

int main()
{
int main() {
vector<int> vec = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
printvec(vec);
insertsort(vec);
Expand Down
18 changes: 6 additions & 12 deletions basic/sorting/InsertionSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,21 @@ func main() {

using namespace std;

void printvec(const vector<int> &vec, const string &strbegin = "", const string &strend = "")
{
void printvec(const vector<int>& vec, const string& strbegin = "", const string& strend = "") {
cout << strbegin << endl;
for (auto val : vec)
{
for (auto val : vec) {
cout << val << "\t";
}

cout << endl;
cout << strend << endl;
}

void insertsort(vector<int> &vec)
{
for (int i = 1; i < vec.size(); i++)
{
void insertsort(vector<int>& vec) {
for (int i = 1; i < vec.size(); i++) {
int j = i - 1;
int num = vec[i];
for (; j >= 0 && vec[j] > num; j--)
{
for (; j >= 0 && vec[j] > num; j--) {
vec[j + 1] = vec[j];
}

Expand All @@ -124,8 +119,7 @@ void insertsort(vector<int> &vec)
return;
}

int main()
{
int main() {
vector<int> vec = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
printvec(vec);
insertsort(vec);
Expand Down
15 changes: 7 additions & 8 deletions basic/sorting/MergeSort/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@ int n;
int nums[N];
int tmp[N];

void merge_sort(int nums[], int left, int right)
{
void merge_sort(int nums[], int left, int right) {
if (left >= right) return;
int mid = (left + right) >> 1;
merge_sort(nums, left, mid);
merge_sort(nums, mid + 1, right);
int i = left, j = mid + 1, k = 0;
while (i <= mid && j <= right)
{
if (nums[i] <= nums[j]) tmp[k++] = nums[i++];
else tmp[k++] = nums[j++];
while (i <= mid && j <= right) {
if (nums[i] <= nums[j])
tmp[k++] = nums[i++];
else
tmp[k++] = nums[j++];
}
while (i <= mid) tmp[k++] = nums[i++];
while (j <= right) tmp[k++] = nums[j++];
for (i = left, j = 0; i <= right; ++i, ++j) nums[i] = tmp[j];
}

int main()
{
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &nums[i]);
Expand Down
15 changes: 7 additions & 8 deletions basic/sorting/MergeSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,25 +285,24 @@ int n;
int nums[N];
int tmp[N];

void merge_sort(int nums[], int left, int right)
{
void merge_sort(int nums[], int left, int right) {
if (left >= right) return;
int mid = (left + right) >> 1;
merge_sort(nums, left, mid);
merge_sort(nums, mid + 1, right);
int i = left, j = mid + 1, k = 0;
while (i <= mid && j <= right)
{
if (nums[i] <= nums[j]) tmp[k++] = nums[i++];
else tmp[k++] = nums[j++];
while (i <= mid && j <= right) {
if (nums[i] <= nums[j])
tmp[k++] = nums[i++];
else
tmp[k++] = nums[j++];
}
while (i <= mid) tmp[k++] = nums[i++];
while (j <= right) tmp[k++] = nums[j++];
for (i = left, j = 0; i <= right; ++i, ++j) nums[i] = tmp[j];
}

int main()
{
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &nums[i]);
Expand Down
15 changes: 7 additions & 8 deletions basic/sorting/QuickSort/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ const int N = 1e6 + 10;
int n;
int nums[N];

void quick_sort(int nums[], int left, int right)
{
void quick_sort(int nums[], int left, int right) {
if (left >= right) return;
int i = left - 1, j = right + 1;
int x = nums[left + right >> 1];
while (i < j)
{
while (nums[++i] < x);
while (nums[--j] > x);
while (i < j) {
while (nums[++i] < x)
;
while (nums[--j] > x)
;
if (i < j) swap(nums[i], nums[j]);
}
quick_sort(nums, left, j);
quick_sort(nums, j + 1, right);
}

int main()
{
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &nums[i]);
Expand Down
15 changes: 7 additions & 8 deletions basic/sorting/QuickSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,22 @@ const int N = 1e6 + 10;
int n;
int nums[N];

void quick_sort(int nums[], int left, int right)
{
void quick_sort(int nums[], int left, int right) {
if (left >= right) return;
int i = left - 1, j = right + 1;
int x = nums[left + right >> 1];
while (i < j)
{
while (nums[++i] < x);
while (nums[--j] > x);
while (i < j) {
while (nums[++i] < x)
;
while (nums[--j] > x)
;
if (i < j) swap(nums[i], nums[j]);
}
quick_sort(nums, left, j);
quick_sort(nums, j + 1, right);
}

int main()
{
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &nums[i]);
Expand Down
35 changes: 13 additions & 22 deletions basic/sorting/SelectionSort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,44 +97,35 @@ func main() {

using namespace std;

void printvec( const vector<int> &vec, const string &strbegin = "", const string &strend = "" )
{
void printvec(const vector<int>& vec, const string& strbegin = "", const string& strend = "") {
cout << strbegin << endl;
for ( auto val : vec )
{
for (auto val : vec) {
cout << val << "\t";
}

cout << endl;
cout << strend << endl;
}


void selectsort( vector<int> & vec )
{
for ( int i = 0; i < vec.size() - 1; i++ )
{
void selectsort(vector<int>& vec) {
for (int i = 0; i < vec.size() - 1; i++) {
int minidx = i;
for ( int j = i + 1; j < vec.size(); j++ )
{
if ( vec[minidx] > vec[j] )
{
for (int j = i + 1; j < vec.size(); j++) {
if (vec[minidx] > vec[j]) {
minidx = j;
}
}

swap( vec[i], vec[minidx] );
swap(vec[i], vec[minidx]);
}
}


int main( void )
{
vector<int> vec = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
printvec( vec );
selectsort( vec );
printvec( vec, "after insert sort" );
return(0);
int main(void) {
vector<int> vec = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
printvec(vec);
selectsort(vec);
printvec(vec, "after insert sort");
return (0);
}
```
Expand Down
Loading

0 comments on commit e350ace

Please sign in to comment.