![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
代码练习
Marcus_Liew
简单的人 简单的梦想
展开
-
打乱数组顺序
#include <stdio.h>#include <stdlib.h>#include <time.h>#define ARRAY_SIZE 50int ElementSwitch(int a[], int first, int second){ int tmp; tmp = a[first]; a[first] = a[second]; a[second] = tmp; return 0;}int Shuffle(int a[].原创 2021-09-24 13:03:24 · 362 阅读 · 1 评论 -
C 基本线程
#include <stdio.h>#include "tinycthread.h"int SayHello(char *name){ printf("Run in new thread [%#x]: Hello, %s\n", thrd_current(), name); return 0;}int main(void){ thrd_t new_thread; int result = thrd_create(&new_thread, SayHello, .原创 2021-09-23 17:55:43 · 108 阅读 · 0 评论 -
N的阶乘,递归
#include <stdio.h>unsigned Factorial(unsigned n){ if(n == 0){ return 1; } else{ return n * Factorial(n - 1); }}int main(void){ printf("3! %d\n", Factorial(3)); printf("5! %d\n", Factorial(5)); printf("8! %d\n", Factorial(8)).原创 2021-09-23 15:12:44 · 161 阅读 · 0 评论 -
C语言 变长参数
#include <stdio.h>#include <stdarg.h>void HandleVarargs(int arg_count, ...){ //定义 va_list用于获取变长参数 va_list args; //开始便利 va_start(args, arg_count); for (int i = 0; i < arg_count; ++i) { //取出对应参数 int arg = va_arg(args, int).原创 2021-09-23 14:42:29 · 82 阅读 · 0 评论 -
建立一个菜单用来控制链表
/*名称:菜单功能:建立一个菜单用来控制链表接收:void返回:int*/int menulink(void){ struct node *head = NULL; int data = 0, deldata = 0; int choose; printf("************* LINK LIST MENU *************\n"); printf("\t1原创 2014-03-07 22:08:23 · 1136 阅读 · 0 评论 -
(二)函数定义文件
#include "seqlist.h"//1 创建一个顺序表int create_SqList(SqListPtr L){ for (int i = 0; i < LISTMAXSIZE; i++) L->data[i] = 0; L->length = 0; return 0;}//2 判断顺序表是否为空int isEmpty_SqList(SqList L){ re原创 2014-03-14 17:26:50 · 727 阅读 · 0 评论 -
(三)线性表菜单
#include "seqlist.h"int main(){ //定义一个线性表变量 SqList sqlist; int choose, position, value; do{ printf("************ seqlist menu ************\n"); printf("\t1 创建顺序表\n"); printf("\t2 判断顺序表是否为空原创 2014-03-14 17:27:34 · 960 阅读 · 0 评论 -
(一)线性表头文件
#include #include #ifndef LISTMAXSIZE#define LISTMAXSIZE 10#endif//定义一个顺序表typedef struct SqList{ int data[LISTMAXSIZE]; int length;}SqList, *SqListPtr;//1 创建一个顺序表int create_SqList(SqList原创 2014-03-14 17:25:55 · 7101 阅读 · 0 评论 -
(三)顺序栈main函数
#include "seqstack.h"int main(){ SeqStack stack; initSeqStack(&stack); printf("%d\n", isEmptySeqStack(stack)); PushSeqStack(&stack, 111); PushSeqStack(&stack,原创 2014-03-18 21:05:46 · 3070 阅读 · 2 评论 -
合并两个线性表
/*名称:合并两个线性表功能:从B中查找元素,如果该元素A中没有,则将该元素合并到表A中接收:指向表a的指针,指向表b的指针返回:int*/int union_linerlist(int *a, int *b){ //count用来做脚标,当有值插入到数组中后,count+1,往后挪一位,继续等待插入 //初始化为5,则指向了第一个空位(数组a长度为10,前5位是有值的,后五位为0原创 2014-03-10 15:36:39 · 1353 阅读 · 0 评论 -
删除链表节点
/*名称:删除链表节点功能:删除一个链表节点接收:链表头节点head, 要删除节点的int型数据返回:int*/int deleteLink(struct node* L, int data){ //delPtr指向要被删除的节点 //prePtr指向要被删除的节点的前一个节点 struct node * delPtr; struct node * prePtr; //让两个原创 2014-03-07 16:46:05 · 795 阅读 · 0 评论 -
尾插法插入链表节点
/*名称:尾插法插入链表节点功能:在链表尾部插入一个链表节点接收:链表头节点, 插入节点的int型数据返回:int*/int insertLink_rear(struct node* L, int data){ //rearPtr 用来指向头节点,沿链表行进,最后用来指向最后一个非空节点 struct node * rearPtr; //nodePtr 用来指向新节点 stru原创 2014-03-07 12:14:50 · 2014 阅读 · 1 评论 -
打印链表
/*名称:打印链表功能:打印链表各节点接收:链表头节点head返回:int*/int printLink(struct node* L){ //创建一个结构体指针 struct node * nodePtr; //让这个指针指向头节点的下一个节点 nodePtr = L->next; //当这个节点非空时 while (nodePtr != NULL){ //打印这个节原创 2014-03-07 12:28:19 · 982 阅读 · 0 评论 -
头插法插入链表节点
/*名称:头插法插入链表节点功能:在链表头节点后插入一个链表节点接收:链表头节点head, 插入节点的int型数据返回:int*/int insertLink_head(struct node* L, int data){ //定义一个指向链表节点的指针 struct node *nodePtr; //当链表为空链表时 if ((L->next) == NULL){ //给原创 2014-03-07 15:09:51 · 1517 阅读 · 0 评论 -
二叉树的建立 与 遍历
#include #include //定义一个树节点的结构struct treeNode{ char data; struct treeNode *lchild, *rchlid;};//创建树的各个节点int create_tree(struct treeNode**);//遍历二叉树int show_tree(struct treeNode*);int main(原创 2014-03-13 15:13:31 · 638 阅读 · 0 评论 -
初始化一棵树
#include #include //定义一个树节点的结构struct treeNode{ char data; struct treeNode *lchild, *rchlid;};//初始化一棵树的根节点int initial_tree(struct treeNode**);int main(){ //定义一个指向树节点的指针,并初始化为空 struct tre原创 2014-03-13 12:39:02 · 3564 阅读 · 1 评论 -
链表学习笔记(一)
从这篇博文学到的,由衷感谢panda点击打开链接/*名称:初始化链表(1)(直接改变主调函数中的指针head)功能:制造一个头节点接收:指向节点的指针地址 &head返回:int*/int ref_initLink(struct node **L){ //L为指向head(指向节点的指针)的指针,用L接收head的地址 //L接收到head的地址(&head)后,用malloc原创 2014-03-06 11:56:41 · 612 阅读 · 0 评论 -
Fibonacci
点击(此处)折叠或打开 #include stdio.h> int main(){ /* declaration the variable */ int i_end;原创 2014-03-05 17:06:55 · 449 阅读 · 0 评论 -
(一)链表函数定义文件
#include "linklist.h"int create_linklist(linklistPtr* L){ if(!((*L) = (linklistPtr)malloc(sizeof(linklist)))) return 1; (*L)->data = 234; (*L)->next =NULL; return 0; }原创 2014-03-15 23:41:55 · 647 阅读 · 0 评论 -
(二)链表头文件
#include #include //define a link node structtypedef struct linklistnode{ int data; struct linklistnode *next;}linklist, *linklistPtr;//declaration create_linklistint create_linklist(l原创 2014-03-15 23:43:22 · 920 阅读 · 0 评论 -
(三)链表main函数
#include "linklist.h"int main(){ linklistPtr head; create_linklist(&head); printf("%d\n", head->data); insert_linklist(&head); traversal_linklist(head); del_linklis原创 2014-03-15 23:44:20 · 2510 阅读 · 0 评论 -
show_ip.sh
#!/bin/bash##ip_addr=$(ifconfig | grep "inet addr" | grep -v "127" | awk '{print $2}'| awk -F ':' '{print $2}')echo "your ip address is ${ip_addr}"your ip address is 172.16.54.207原创 2015-12-11 13:23:27 · 539 阅读 · 0 评论 -
mygrep
#!/bin/bash##grep $1 /etc/passwd原创 2015-12-11 11:09:13 · 468 阅读 · 0 评论 -
mytrans.sh
#!/bin/bash##echo "the first para is $1"echo "the second para is $2"echo "the third para is $3"echo "the number of para is $#"echo "the para are $*"echo "the PID is $$"echo "the last PID is $原创 2015-12-11 11:31:11 · 443 阅读 · 0 评论 -
hello
#!/bin/bash##function say_hello(){ echo "Enter your name:" read name echo "Hello ${name}"}echo "Programme start here......"say_helloecho "Programme Ends."原创 2015-12-10 16:01:43 · 265 阅读 · 0 评论 -
清理/var/log/messages的脚本
#!/bin/bash#this is clearcat /dev/null > /var/log/messagesecho "message clear up"原创 2015-12-10 15:21:46 · 2338 阅读 · 0 评论 -
where are you
#!/bin/bash##echo "you are in the `pwd`"原创 2015-12-10 16:10:12 · 418 阅读 · 0 评论 -
一个简单的类 和 调用
#include using namespace std;class Time{public: //构造函数 Time(); //设置时间函数 void setTime(int, int, int); //24小时制显示时间 void showTime24(); //12小时制显示时间 void showTime12();private: int hour; int原创 2014-03-21 12:51:32 · 521 阅读 · 0 评论 -
简单的函数模版
#include using namespace std;template T volume(T side1, T side2, T side3){ return side1 * side2 * side3;}int main(){ cout << volume(1, 2, 3) << endl; cout << volume(1.2, 2.0, 3.3) << endl;原创 2014-03-20 11:32:19 · 516 阅读 · 0 评论 -
function overload 2
#include #include using namespace std;int square(int);double square(double);int main(){ cout << square(8) << endl; cout << square(9.3) << endl; return 0;}int square(int edge){原创 2014-03-19 23:25:12 · 773 阅读 · 0 评论 -
function overload
#include #include using namespace std;int square(int);double square(double);int main(){ cout << square(8) << endl; cout << square(9.3) << endl; return 0;}int square(int edge){原创 2014-03-19 23:17:57 · 694 阅读 · 0 评论 -
(二)顺序栈函数定义
#include "seqstack.h"int initSeqStack(SeqStack* S){ S->top = 0; return 0;}int clearSeqStack(SeqStack* S){ for (int i=0; itop; i++) S->data[i] = 0; S->top = 0; return 0原创 2014-03-18 21:04:53 · 853 阅读 · 0 评论 -
(一)顺序栈头文件
#include #include #define STACKMAXSIZE 10typedef struct seqstack{ int data[STACKMAXSIZE]; int top;}SeqStack;int initSeqStack(SeqStack*);int destroySeqStack(SeqStack*);int clearS原创 2014-03-18 21:03:46 · 1648 阅读 · 0 评论 -
一个斐波那契数列
#include #define FIBONSIZE 20int main(){ int a = 0, b = 1, c, fibon[FIBONSIZE]; for (int i = 0; i < FIBONSIZE; i++){ c = a + b; fibon[i] = c; a = b; b = c; } for (int i = 0; i < FIBONS原创 2014-03-18 09:31:55 · 515 阅读 · 0 评论 -
读取系统时间作为seed 随机打印数字
点击(此处)折叠或打开 #include stdio.h> #include stdlib.h> #include time.h> int main(){原创 2014-03-05 17:06:58 · 1334 阅读 · 0 评论 -
顺序栈的一般操作
#include //define the size of array#define MAXSIZE 100//define new data type: stackstruct stack{ int data[MAXSIZE]; int top;};//defint var seqStacktypedef struct stack seqStack;//crea原创 2014-03-11 22:28:51 · 509 阅读 · 0 评论 -
线性表操作
/***name: create a seqlistreceive: seqlist addressreturn: int***/int creat(Seqlist* L){ int len; L->length = 0; printf("Enter the length of the seqlist:"); scanf("%d", &len); if (len <= 100)原创 2014-03-11 16:30:56 · 556 阅读 · 0 评论 -
通过两条边 计算直角三角形第三条边
#include #include double hypotenuse(double, double);int main(){ double x, y; x = 5; y = 12; printf("%lf", hypotenuse(x, y));}//计算直角三角形第三条边double hypotenuse(double a, double b){原创 2014-03-05 16:58:53 · 5100 阅读 · 0 评论 -
计算a的b次方
#include int integer(int, int);int main(){ int base, exponent; scanf("%d%d", &base, &exponent); printf("the result is: %d\n", integer(base, exponent)); return 0;}int integer(int原创 2014-03-05 16:58:00 · 2085 阅读 · 0 评论 -
判断一组数中 两两一对的数 后者是否是前者的倍数
#include int multiple(int, int);int main(){ int x, y, tmp, counter = 0; printf("please enter some parts of integer(-1 to end):\n"); scanf("%d%d", &x, &y); while(-1 != x && -1 != y)原创 2014-03-05 16:57:09 · 783 阅读 · 0 评论