1.思维导图
2.写一个函数,获取用户的uid和gid并使用变量接收
#!/bin/bash
fun()
{
uid=$(id -u)
gid=$(id -g)
}
fun
echo $uid $gid
3.整理冒泡排序、选择排序和快速排序的代码
冒泡
#include <myhead.h>
void fun(int l,int *arr)
{
for(int i=0;i<l-1;i++)
{
for(int j=0;j<l-1-i;j++)
{
if(arr[j]>arr[j+1])
{
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
}
}
}
int main(int argc,const char *argv[])
{
int t[]={1,6,9,4,2,8,90,2,13,5};
int len=sizeof(t)/sizeof(t[0]);
fun(len,t);
for(int i=0;i<len;i++)
{
printf("%d ",t[i]);
}
printf("\n");
return 0;
}
选择排序
#include <myhead.h>
void fun(int l,int *arr)
{
for(int i=0;i<l-1;i++)
{
int key = i;
for(int j=i;j<l;j++)
{
if(arr[key] > arr[j])
{
key = j;
}
}
if(key != i)
{
int t = arr[key];
arr[key] = arr[i];
arr[i] = t;
}
}
}
int main(int argc,const char *argv[])
{
int t[]={1,6,9,4,2,8,90,2,13,5};
int len=sizeof(t)/sizeof(t[0]);
fun(len,t);
for(int i=0;i<len;i++)
{
printf("%d ",t[i]);
}
printf("\n");
return 0;
}
快排
#include <myhead.h>
void fun(int *arr,int min,int max)
{
if(min>=max) return;
int low = min;
int high = max;
int key = arr[min];
while (low < high)
{
while (low < high)
{
if(key > arr[high])
{
arr[low] = arr[high];
low++;
break;
}
high--;
}
while (low < high)
{
if(key < arr[low])
{
arr[high] = arr[low];
high--;
break;
}
low++;
}
}
arr[low] = key;
fun(arr,min,low-1);
fun(arr,low+1,max);
}
int main(int argc,const char *argv[])
{
int t[]={1,6,9,4,2,8,90,2,13,5};
int len=sizeof(t)/sizeof(t[0]);
fun(t,0,len-1);
for(int i=0;i<len;i++)
{
printf("%d ",t[i]);
}
printf("\n");
return 0;
}