序号 |
标题 |
代码 |
编程语言 |
最后编辑时间 |
浏览次数 |
1
|
链表
|
/**
* Created on: 2016年09月18日 18:29:35
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
*/
#include <stdio.h>
typedef struct {
char key[15]; //关键字
char name[20];
int age;
} DATA; //数据结点类型
#include <stdlib.h>
typedef struct Node {
DATA data;
struct Node *next;
} ChainListType;
ChainListType *ChainListAddEnd(ChainListType *head,DATA data); //添加结点到链表末尾
ChainListType *ChainListAddFirst(ChainListType *head,DATA data); //添加结点到链表首部
ChainListType *ChainListFind(ChainListType *head,char *key); //按关键字在链表中查找内容
ChainListType *ChainListInsert(ChainListType *head,char *findkey,DATA data); //插入结点到链表指定位置
int ChainListDelete(ChainListType *head,char *key);//删除指定关键字的结点
int ChainListLength(ChainListType *head);//获取链表结点数量
//#include "2-5 ChainList.c"
#include <string.h>
ChainListType *ChainListAddEnd(ChainListT ...
|
C/C++
|
2017-07-04 20:05:54
|
289
|
2
|
查找算法
|
|
C/C++
|
2017-07-05 11:30:48
|
252
|
3
|
作用域
|
/**
* Created on: 2016年09月21日 20:24:58
* Author: jtahstu
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
* 作用域
*/
#include <stdio.h>
void fun(){
int a=3,b;
printf("fun()函数里面的a的值为:%d\n",a);
return ;
}
int main()
{
int a=0,b;
{
int a=1;
printf("main()函数里面被大括号封装的a的值为:%d\n",a);
}
fun();
printf("mian()函数里面的a的值为:%d\n",a);
return 0;
}
|
C/C++
|
2017-06-22 14:17:23
|
239
|
4
|
静态局部变量
|
/**
* Created on: 2016年09月21日 20:31:59
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
* 静态局部变量
*/
#include <stdio.h>
void print(){
static int a=0;
printf("静态局部变量a=%d\n",a++);
}
int main()
{
print();
print();
return 0;
}
|
C/C++
|
2017-07-03 17:47:05
|
237
|
5
|
指针数组和数组指针
|
/**
* Created on: 2016年09月21日 20:33:28
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
* 指针数组和数组指针
*/
#include <stdio.h>
int main()
{
int arr[4][4]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int (*p1)[4];
int *p2[4];
int i,j,k;
p1=arr;
printf("使用数组指针的方式访问二维数组arr\n");
for(i=0;i<4;i++){
for(j=0;j<4;j++){
printf("arr[%d][%d]=%d\t",i,j,*(*(p1+i)+j));
}
printf("\n");
}
printf("\n使用指针数组的方式访问二维数组arr\n");
for(k=0;k<4;k++)
p2[k]=arr[k];
for(i=0;i<4;i++){
for(j=0;j<4;j++){
printf("arr[%d][%d]=%d\t",i,j,*(p2[i]+j));
}
printf("\n");
}
return 0;
}
|
C/C++
|
2017-06-22 14:17:31
|
249
|
6
|
二维数组
|
/**
* Created on: 2016年09月21日 20:46:41
* Author: jtahstu
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
* 其他表示二维数组每行起始地址的方式
*/
#include <stdio.h>
int main()
{
int arr[4][4]={0,1,2,3,4,5,6,7,8,9,10,1,12,13,14,15};
int i;
for (int i = 0; i < 4; i++) {
printf("第%d行的起始地址为:%d\n",i+1,arr+i);
printf("第%d行的起始地址为:%d\n",i+1,arr[i]);
printf("第%d行的起始地址为:%d\n",i+1,*(arr+i));
printf("第%d行的起始地址为:%d\n\n",i+1,&arr[i]);
}
return 0;
}
|
C/C++
|
2017-06-22 22:37:43
|
248
|
7
|
顺序队列
|
/**
* Created on: 2016年09月22日 12:37:52
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
*/
//顺序队列操作
#define QUEUEMAX 15
typedef struct {
DATA data[QUEUEMAX]; //队列数组
int head; //队头
int tail; //队尾
} SeqQueue;
SeqQueue *SeqQueueInit() {
SeqQueue *q;
if(q=(SeqQueue *)malloc(sizeof(SeqQueue))) { //申请保存队列的内存
q->head = 0;//设置队头
q->tail = 0;//设置队尾
return q;
} else
return NULL; //返回空
}
void SeqQueueFree(SeqQueue *q) { //释放队列
if (q!=NULL)
free(q);
}
int SeqQueueIsEmpty(SeqQueue *q) { //队列是否为空
return (q->head==q->tail);
}
int SeqQueueIsFull(SeqQueue *q) { //队列是否已满
return (q->tail==QUEUEMAX);
}
int SeqQueueLen(SeqQueue *q) { //获取队列长度
return(q->tail-q->head);
}
int SeqQueueIn(SeqQueue *q,DATA data) { //顺序队列的入队函数
if(q->tail==QUEUEMAX) {
printf(" ...
|
C/C++
|
2017-06-30 23:38:36
|
284
|
8
|
循环队列
|
/**
* Created on: 2016年09月22日 12:37:52
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
*/
//循环队列
#define QUEUEMAX 15
typedef struct {
DATA data[QUEUEMAX]; //队列数组
int head; //队头
int tail; //队尾
} CycQueue;
CycQueue *CycQueueInit() {
CycQueue *q;
if(q=(CycQueue *)malloc(sizeof(CycQueue))) { //申请保存队列的内存
q->head = 0;//设置队头
q->tail = 0;//设置队尾
return q;
} else
return NULL; //返回空
}
void CycQueueFree(CycQueue *q) { //释放队列
if (q!=NULL)
free(q);
}
int CycQueueIsEmpty(CycQueue *q) { //队列是否为空
return (q->head==q->tail);
}
int CycQueueIsFull(CycQueue *q) { //队列是否已满
return ((q->tail+1)%QUEUEMAX==q->head);
}
int CycQueueIn(CycQueue *q,DATA data) { //入队函数
if((q->tail+1)%QUEUEMAX == q->head ) {
printf("队列已满!\n");
return 0;
} else {
q->tail=(q->tail+ ...
|
C/C++
|
2017-07-02 01:03:33
|
249
|
9
|
约瑟夫环
|
/**
* Created on: 2016年09月22日 15:36:35
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
*/
//约瑟夫环
#include <stdio.h>
#include <stdlib.h>
#define N 41 //总共的人数
#define M 3 //每多少个自杀
int main() {
int man[N]= {0};
int count=1;
int i=0,pos=-1;
int alive=0;
while(count<=N) {
do {
pos=(pos+1) % N; //环状处理
if(man[pos]==0)
i++;
if(i==M) { //报数3的人
i=0;
break;
}
} while(1);
man[pos]=count;
count++;
}
printf("\n约瑟夫排列(最初位置-约瑟夫环位置):\n");
for(i=0; i<N; i++) {
printf("%d-%d ",i+1,man[i]);
if(i!=0 && i%10==0) //每输出10个则换行
printf("\n");
}
printf("\n\n准备剩下的人数?");
scanf("%d", &alive);
printf("这%d人初始位置应排在以下序号:\n",alive);
alive=N-a ...
|
C/C++
|
2017-06-22 14:17:44
|
231
|
10
|
二路归并算法合并两个有序表
|
/**
* Created on: 2016年10月10日 20:42:56
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
* 有两个有序表A和B,且A、B不存在重复元素,将他们合并成一个有序表C
* 二路归并算法
*/
#include<iostream>
#include<algorithm>
using namespace std;
const int SIZE=5;
int A[SIZE+1]={1,3,5,7,8},B[SIZE+1]={2,4,6,9,10};
int C[SIZE*2+1];
void UnionList(int A[],int B[],int C[]){
int i=0,j=0,k=0;
while(i<SIZE&&j<SIZE){
if(A[i]<B[j]){
C[k]=A[i];
i++;
k++;
}else{
C[k]=B[j];
j++;
k++;
}
}
while(i<SIZE){
C[k]=A[i];
i++;
k++;
}
while(j<SIZE){
C[k]=B[j];
j++;
k++;
}
}
int main(){
int A[SIZE+1]={1,3,5,7,8},B[SIZE+1]={2,4,6,9,10};
UnionList(A,B,C);
for (int i = 0; i < SIZE*2; i++) {
cout << C[i] << " ";
}
return 0;
}
|
C/C++
|
2017-06-22 14:16:50
|
266
|
11
|
删除有序单链表重复的节点
|
/**
* Created on: 2016年10月10日 21:36:11
* Author: jtahstu
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
*/
void dels(LinkList *&L){
LinkList *p=L->next,*q;
while(p->next!=NULL){
if(p->data==p->next->data){
q=p->next;
p->next=q->next;
free(q);
}else{
p=p->next;
}
}
}
|
C/C++
|
2017-07-04 04:47:36
|
272
|
12
|
单链表
|
/**
* Created on: 2016年10月13日 01:01:54
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
*/
// LinkList.cpp : 定义控制台应用程序的入口点。
// 单链表
#include<iostream>
#include<malloc.h>
using namespace std;
typedef int ElemType;
typedef struct LNode {
ElemType data;
struct LNode *next;
}LinkList;
//头插法建表,按原数组倒序排列
void CreateListF(LinkList *&L, ElemType a[], int n) {
LinkList *s;
L = (LinkList *)malloc(sizeof(LinkList));
//L->data = 0; //表头有一个空的节点
L->next = NULL; //创建头结点,其next域置为NULL
for (int i = 0; i < n; i++) {
s = (LinkList *)malloc(sizeof(LinkList));
s->data = a[i];
s->next = L->next; //将*s插在原开始节点之前,头结点之后
L->next = s;
}
}
//尾插法建表,按原数组顺序排列
void CreateListR(LinkList *&L, ElemType a[], int n) {
LinkList *s, *r;
L = (LinkList *)malloc(sizeof(LinkList)); //创建头结点
//L->data = 0; ...
|
C/C++
|
2017-07-04 00:12:31
|
280
|
13
|
2333
|
<?php
/**
* Created on: 2016年10月14日 18:10:07
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
*/
echo 'Hello World!';
?>
|
PHP
|
2017-06-22 14:16:59
|
245
|
14
|
汉诺塔(递归)
|
/**
* Created on: 2016年10月23日 15:27:25
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
* 汉诺塔,递归
*/
#include<iostream>
#include<stdio.h>
using namespace std;
long long count; //全局变量, 记录移动的次数
void hanoi(int n,char a,char b,char c) { //a移到b,用c作临时柱
if(n==1) {
printf("第%lld次,%c棒-->%c棒\n",++count,a,c);
} else {
hanoi(n-1,a,c,b); //递归调用本函数,移动a到c,用b作临时柱
printf("第%lld次,%c棒-->%c棒\n",++count,a,c);
hanoi(n-1,b,a,c); //递归调用本函数,将b移到a,用c作临时柱
}
}
int main() {
int h; //圆盘数量
printf("请输入汉诺塔圆盘的数量:");
// scanf("%d",&h);
h=5;
count=0;
hanoi(h,'A','B','C');
printf("Ok,程序到此结束!");
return 0;
}
|
C/C++
|
2017-07-02 10:18:20
|
226
|
15
|
作者真懒,题目都不写 ╮(╯_╰)╭
|
#!/bin/bash
echo 'Hello World!'
|
Bash
|
2017-07-01 20:12:24
|
283
|
16
|
共用体访问
|
/**
* Created on: 2016年11月24日 21:31:06
* Author: Guest
* Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
*/
#include <stdio.h>
union abc{
int i;
char c[2];
}x;
int main()
{
x.c[0]=0;
x.c[1]=1;
printf("%d %d %x\n",x.c[0],x.c[1],x.i);
x.c[0]=10; //这个就相当于个位
x.c[1]=1; //这位相当于十位,权重为256
printf("%d %d %x",x.c[0],x.c[1],x.i);
return 0;
}
/*
所以第一个就是:1*256+0
第二个是:1*256+10
*/
|
C/C++
|
2017-06-30 20:16:16
|
307
|
17
|
测试分享
|
# -*- coding: UTF-8 -*-
# Created on: 2016年12月31日 17:13:39
# Author: Guest
# Copyright (c) 2016, tool.usta.wiki , All Rights Reserved.
print 'Hello World!'
|
Python
|
2017-07-01 14:48:45
|
201
|
18
|
作者真懒,题目都不写 ╮(╯_╰)╭
|
/**
* Created on: 2017年01月20日 23:50:15
* Author: Guest
* Copyright (c) 2017, tool.usta.wiki , All Rights Reserved.
*/
#include <stdio.h>
int main()
{
// 我的第一个 C 程序
printf("Hello, World! \n");
return 0;
}
|
C/C++
|
2017-07-05 17:17:20
|
191
|
19
|
作者真懒,题目都不写 ╮(╯_╰)╭
|
<?php
/**
* Created on: 2017年02月09日 11:09:58
* Author: Guest
* Copyright (c) 2017, tool.usta.wiki , All Rights Reserved.
*/
echo 'Hello World!';
|
PHP
|
2017-07-04 05:41:16
|
193
|
20
|
111
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>iTool - 在线代码编辑</title>
</head>
<body>
<h1>我的第一个标题</h1>
<p>我的第一个段落。</p>
</body>
</html>
|
HTML/CSS/JS
|
2017-07-01 02:29:59
|
185
|