Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added a
Empty file.
3 changes: 3 additions & 0 deletions assignments/shell/TraverseDir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
杜伊涵 22920142203807
shell作业:
写一个shell脚本TraverseDir.sh遍历输出当前目录及其子目录下的所有文件和目录。
3 changes: 3 additions & 0 deletions assignments/shell/TraverseDir/README.md~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
杜伊涵 22920142203807
shell作业:
写一个shell脚本TraverseDir.sh遍历当前目录及其子目录下的所有文件和目录。
15 changes: 15 additions & 0 deletions assignments/shell/TraverseDir/TraverseDir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
function traverse_dir()
{
for file in $1/*
do
if [ -d $file ]
then
traverse_dir $file
else
echo $file
fi
done
}
traverse_dir $PWD

6 changes: 6 additions & 0 deletions experiments/gcc-1-hello-world/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
main:main.o
gcc main.o -o main
main.o:main.c
gcc -c main.c
clean:
rm main *.o
Empty file.
Binary file added experiments/gcc-1-hello-world/mian
Binary file not shown.
9 changes: 9 additions & 0 deletions experiments/gcc-2-multi-source/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
main:main.o calculator.o
gcc main.o calculator.o -o main
main.o:main.c
gcc -c main.c
calculator.o:calculator.c
gcc -c calculator.c

clean:
rm main *.o
9 changes: 7 additions & 2 deletions experiments/gcc-2-multi-source/calculator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "include/calculator.h"

#include <stdio.h>
int sum(int x, int y) {
return x + y;
}
Expand All @@ -13,5 +13,10 @@ int multiply(int x, int y) {
}

int divide(int x, int divisor) {
return x / divisor;
if(divisor==0)
{
printf("Divisor cannot be 0!\n");
return -999999;
}
else return x / divisor;
}
22 changes: 22 additions & 0 deletions experiments/gcc-2-multi-source/calculator.c~
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "include/calculator.h"
#include <stdio.h>
int sum(int x, int y) {
return x + y;
}

int subtract(int x, int y) {
return x - y;
}

int multiply(int x, int y) {
return x * y;
}

int divide(int x, int divisor) {
if(divisor==0)
{
printf("Divisor cannot be 0!\n");
return -999999;
}
else return x / divisor;
}
Binary file added experiments/gcc-2-multi-source/main
Binary file not shown.
5 changes: 4 additions & 1 deletion experiments/gcc-2-multi-source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ int main(void) {
y = 3;

printf("%d + %d = %d\n", x, y, sum(2, 3));

printf("%d - %d = %d\n", x, y, subtract(2, 3));
printf("%d * %d = %d\n", x, y, multiply(2, 3));
printf("%d / %d = %d\n", x, y, divide(2, 3));
printf("1 / 0 = %d\n", divide(1, 0));
return 0;
}
15 changes: 15 additions & 0 deletions experiments/gcc-2-multi-source/main.c~
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>

int main(void) {
int x, y;

x = 2;
y = 3;

printf("%d + %d = %d\n", x, y, sum(2, 3));
printf("%d - %d = %d\n", x, y, subtract(2, 3));
printf("%d * %d = %d\n", x, y, multiply(2, 3));
printf("%d / %d = %d\n", x, y, divide(2, 3));
printf("1 / 0 = %d\n", divide(1, 0));
return 0;
}
9 changes: 7 additions & 2 deletions experiments/gcc-3-real-project/calculator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "include/calculator.h"

#include <stdio.h>
int sum(int x, int y) {
return x + y;
}
Expand All @@ -13,5 +13,10 @@ int multiply(int x, int y) {
}

int divide(int x, int divisor) {
return x / divisor;
if(divisor==0)
{
printf("Divisor cannot be 0!\n");
return -999999;
}
else return x / divisor;
}
22 changes: 22 additions & 0 deletions experiments/gcc-3-real-project/calculator.c~
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "include/calculator.h"

int sum(int x, int y) {
return x + y;
}

int subtract(int x, int y) {
return x - y;
}

int multiply(int x, int y) {
return x * y;
}

int divide(int x, int divisor) {
if(divisor==0)
{
printf("Divisor cannot be 0!\n");
return -999999;
}
else return x / divisor;
}
4 changes: 0 additions & 4 deletions experiments/gcc-3-real-project/include/calculator.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#ifndef _CALC_H
#define _CALC_H

int sum(int x, int y);
int subtract(int x, int y);
int multiply(int x, int y);
int divide(int x, int divisor);

#endif //_CALC_H
9 changes: 9 additions & 0 deletions experiments/gcc-3-real-project/include/calculator.h~
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef _CALC_H
#define _CALC_H

int sum(int x, int y);
int subtract(int x, int y);
int multiply(int x, int y);
int divide(int x, int divisor);

#endif //_CALC_H
Binary file added experiments/gcc-3-real-project/main
Binary file not shown.
5 changes: 4 additions & 1 deletion experiments/gcc-3-real-project/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ int main(void) {
x = 2;
y = 3;

printf("%d + %d = %d\n", x, y, sum(2, 3));
printf("%d - %d = %d\n", x, y, subtract(2, 3));

printf("%d * %d = %d\n", x, y, multiply(2, 3));
printf("%d / %d = %d\n", x, y, divide(2, 3));
printf("1 / 0 = %d\n", divide(1, 0));
return 0;
}
17 changes: 17 additions & 0 deletions experiments/gcc-3-real-project/main.c~
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>

#include "include/calculator.h"

int main(void) {
int x, y;

x = 2;
y = 3;

printf("%d + %d = %d\n", x, y, sum(2, 3));
printf("%d - %d = %d\n", x, y, subtract(2, 3));
printf("%d * %d = %d\n", x, y, multiply(2, 3));
printf("%d / %d = %d\n", x, y, divide(2, 3));
printf("1 / 0 = %d\n", divide(1, 0));
return 0;
}
9 changes: 7 additions & 2 deletions experiments/gcc-4-optimize/calculator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "include/calculator.h"

#include <stdio.h>
int sum(int x, int y) {
return x + y;
}
Expand All @@ -13,5 +13,10 @@ int multiply(int x, int y) {
}

int divide(int x, int divisor) {
return x / divisor;
if(divisor==0)
{
printf("Divisor cannot be 0!\n");
return -999999;
}
else return x / divisor;
}
4 changes: 1 addition & 3 deletions experiments/gcc-4-optimize/include/array.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#ifndef _ARRAY_H
#define _ARRAY_H


void array_fill_with(int *array, int length, int fillWith);
void array_print(int *array, int length);

void array_add(int *arrayX, int *arrayY, int *arrayZ, int length);

#endif
9 changes: 9 additions & 0 deletions experiments/gcc-4-optimize/include/array.h~
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef _ARRAY_H
#define _ARRAY_H

void array_fill_with(int *array, int length, int fillWith);
void array_print(int *array, int length);

void array_add(int *arrayX, int *arrayY, int *arrayZ, int length);

#endif
9 changes: 9 additions & 0 deletions final-test/c_cpp/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
main:my_stack.o main.o
gcc my_stack.o main.o -o main
my_stack.o:
gcc -c my_stack.c
main.o:
gcc -c main.c
clean:
if [ -e main ];then rm main;fi;
rm *.o

10 changes: 10 additions & 0 deletions final-test/c_cpp/Makefile~
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
main:my_stack.o main.o
gcc my_stack.o main.o -o main
my_stack.o:
gcc -c my_stack.c
main.o:
gcc -c main.c
clean:
if [ -e main ];then rm main;fi;
if [ -e *.o ];then rm *.o;fi;

37 changes: 36 additions & 1 deletion final-test/c_cpp/my_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,40 @@
* 但是记住g++才是编译C++的编译器
*
*/
#define MAXSIZE 5
int s[MAXSIZE];
int base=0,top=0;
void stack_push(int x)
{
s[top++]=x;
}
int stack_pop()
{
int e;
e=s[--top];
return e;
}
// The capacity of the stack
int stack_capacity()
{
return MAXSIZE;
}
// Current available size of the stack
int stack_size()
{
return top-base;
}


/*
* return 0/1 to check if stack is empty or full
* 0 - No
* 1 - Yes
*/
int stack_is_empty()
{
return top==base;
}
int stack_is_full()
{
return stack_size()==MAXSIZE;
}
43 changes: 43 additions & 0 deletions final-test/c_cpp/my_stack.c~
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* my_stack的实现文件
* 如果采用C++的实现,那也可以把此文件名改为.cpp
* 但是记住g++才是编译C++的编译器
*
*/
#define MAXSIZE 100
int s[MAXSIZE];
int base=0,top=0;
void stack_push(int x)
{
s[top++]=x;
}
int stack_pop()
{
int e;
e=s[--top];
return e;
}
// The capacity of the stack
int stack_capacity()
{
return MAXSIZE;
}
// Current available size of the stack
int stack_size()
{
return top-base;
}

/*
* return 0/1 to check if stack is empty or full
* 0 - No
* 1 - Yes
*/
int stack_is_empty()
{
return top==base;
}
int stack_is_full()
{
return stack_size()==MAXSIZE;
}