1、思维导图
2、写一个shell函数,获取用户的uid和gid并使用变量接收
bash
#!/bin/bash
function get_id()
{
uid=`id -u ubuntu`
gid=`id -g ubuntu`
}
get_id
echo "uid:$uid"
echo "gid:$gid"
运行结果
3、排序
冒泡排序
cpp
/*
---------------------------------
@author:YoungZorn
created on 2023/8/7 19:01.
---------------------------------
*/
#include<iostream>
using namespace std;
void BubbleSort(int *arr,int n){
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j]>arr[j+1]){
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
void output(int *arr,int n){
for (int i = 0; i < n; i++) {
cout<<arr[i]<<" ";
}
}
int main(){
int arr[] = {56,78,12,23,43,90,51,78};
int len = sizeof(arr)/ sizeof(int);
BubbleSort(arr,len);
output(arr,len);
return 0;
}
选择排序
cpp
/*
---------------------------------
@author:YoungZorn
created on 2023/8/7 19:06.
---------------------------------
*/
#include<iostream>
using namespace std;
void SelectSort(int *arr,int n){
for (int i = 0; i < n - 1; i++) {
for (int j = i+1; j < n; j++) {
if (arr[i] > arr[j]){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
void output(int *arr,int n){
for (int i = 0; i < n; i++) {
cout<<arr[i]<<" ";
}
}
int main(){
int arr[] = {12,32,42,54,68,23,85,90,80};
int len = sizeof(arr)/sizeof(int);
SelectSort(arr,len);
output(arr,len);
return 0;
}
快速排序
cpp
/*
---------------------------------
@author:YoungZorn
created on 2023/8/7 19:09.
---------------------------------
*/
#include<iostream>
using namespace std;
int OneSort(int *arr,int low,int high){ //获取基准值
int key = arr[low];
while (low < high){
while (low < high && key <= arr[high]){
high--;
}
arr[low] = arr[high];
while (low < high && key >= arr[low]){
low++;
}
arr[high] = arr[low];
}
arr[low] = key;
return low;
}
void QuickSort(int *arr,int low,int high){
if(low >= high){
return;
}
int mid = OneSort(arr,low,high);
QuickSort(arr,0,mid-1);
QuickSort(arr,mid+1,high);
}
void output(int *arr,int n){
for (int i = 0; i < n; i++) {
cout<<arr[i]<<" ";
}
}
int main(){
int arr[] = {34,12,32,87,52,74,68,30};
int len = sizeof(arr)/ sizeof(int);
QuickSort(arr,0,len-1);
output(arr,len);
return 0;
}