当前位置:首页 » 编程软件 » dk编程真好玩

dk编程真好玩

发布时间: 2023-07-23 09:45:52

❶ 3. 用任意一种编程语言(C/C++/Java/C#/VB.NET)写出任意一种你所知的排序算法(比如:冒泡排序, 归并排

#include<stdio.h>
#include<stdlib.h>
void BubbleSort(int a[], const int first, const int last);//冒泡排序
void InsertSort(int a[], const int first, const int last);//插入排序
void SelectSort(int a[], const int first, const int last);//选择排序
void MergeSort(int a[], const int p, const int r);//合并排序
void QuickSort(int a[],const int p,const int r);//快速排序
void ShellSort(int a[],const int p,const int r,const int dlta[],const int t);//希尔排序
void HeapSort(int a[],const int p, int r); //堆排序
void StoogeSort(int a[],const int p,const int r);//Stooge排序(不用)算法复杂度没算清楚

void main()
{
//插入排序算法
int a[11] = {6,4,5,3,2,1};
int dlta[]={9,5,3,2,1};
//BubbleSort(a,0,5);
//InsertSort(a,0,5);
//SelectSort(a,0,5);
//MergeSort(a,0,5);
//QuickSort(a,0,5);
//ShellSort(a,0,5,dlta,5);
HeapSort(a,0,5);
//StoogeSort(a,0,5);

for(int i=0; i<=5;i++)
{
printf("%d ",a[i]);
}

}

/************************冒泡排序***********************/
void BubbleSort(int a[], int first, int last)
{
//实现对数组a[]中a[first]到a[last]升序的“冒泡”排序
int i,j,temp;
for(i=first; i<=last; i++)
{
for(j=first; j< last-i; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}

/************************插入排序***********************/
void InsertSort(int a[], int first, int last)
{
//实现对数组a[]中a[first]到a[last]升序的“插入”排序
//最坏情况为n的平方,,多用于小数组
int i,j,temp;
for(i=first+1; i<=last; i++)
{
temp = a[i];
j = i - 1;
while((j >= 0) && (a[j] > temp))
{
a[j+1] = a[j];
j--;
}
a[j+1] = temp;
}
}

/************************选择排序***********************/
void SelectSort(int a[], int first, int last)
{
//实现对数组a[]中a[first]到a[last]升序的“选择”排序
int i, j, temp, num;
for(i=first; i<last; i++)
{
num = i;
for(j=i+1; j<=last; j++)
{
if(a[j] < a[num])
{
num = j;
}
}
if(i != num)
{
temp = a[num];
a[num] = a[i];
a[i] = temp;
}
}
}

/************************合并排序***********************/
void Merge(int a[],const int p,const int q,const int r)
{
//合并排序算法中的实现合并的子程序
int iLLength,iRLength;
int *L, *R, i, j, k;
iLLength = q - p + 1;
iRLength = r - q;
L = (int *)malloc(iLLength*sizeof(int)); //或者 C++中 new int[iLLength];
R = (int *)malloc(iRLength*sizeof(int)); //或者 C++中 new int[iRLength];
if(L == 0 || R== 0)
{
printf("内存分配失败!!!");
return;
}
for(i=0; i<iLLength; i++)
{
L[i] = a[p+i];
}
for(j=0; j<iRLength; j++)
{
R[j] = a[q+j+1];
}
i = 0;
j = 0;
for(k=p; k<=r; k++)
{
if((i<iLLength) && (j<iRLength) && (L[i]<=R[j]) || (j == iRLength))
{
a[k] = L[i];
i++;
}
else if(j<iRLength)
{
a[k] = R[j];
j++;
}
}

free(R);free(L);
}
void MergeSort(int a[],const int p,const int r)
{
//合并排序算法-主程序
//n*lg(n),系数较小
int q;
if(p<r)
{
q = (p+r)/2;
MergeSort(a,p,q);
MergeSort(a,q+1,r);
Merge(a,p,q,r);
}
}

/************************Stooge排序***********************/
void StoogeSort(int a[],const int p,const int r)
{
//Stooge算法
int temp, k;
if(a[p]>a[r])
{
temp = a[p];
a[p] = a[r];
a[r] = temp;
}
if((p+1) >= r)
{
return;
}
k = (r-p+1)/3;
StoogeSort(a,p,r-k);
StoogeSort(a,p+k,r);
StoogeSort(a,p,r-k);
}

/************************快速排序*********************/
int QuickPartition(int a[],const int p,const int r)
{
//快速排序的(关键)分治过程
int temp, x, i, j;
x = a[r];
i = p - 1;
for(j=p; j<r; j++)
{
if(a[j] <= x)
{
i = i + 1;
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
temp = a[i+1];
a[i+1] = a[r];
a[r] = temp;
return (i+1);
}
/*
void QuickSort(int a[],const int p,const int r)
{
//快速排序算法-主程序
//与下面的“尾递归实现方法”比较,缺点:右边数组的递归不是必须的,增加了运行堆栈深度和调用开销
int q;
if(p < r)
{
q = QuickPartition(a, p, r);
QuickSort(a, p, q-1);
QuickSort(a, q+1, r);
}
}
*/
void QuickSort(int a[],int p,const int r)
{
//快速排序算法-主程序
//“尾递归实现方法”是对上面的快速排序主程序实现的一种优化
//系数较小,常用大数组
int q;
while(p < r)
{
q = QuickPartition(a, p, r);
QuickSort(a, p, q-1);
p = q + 1;
}
}

/************************希尔排序**********************/
void ShellInsert(int a[],const int p,const int r, int dk)
{
//希尔排序算法的关键子程序-插入排序子程序
int i, j, temp;
for(i=p+dk; i<=r; i++)
{
if(a[i] < a[i-dk])
{
temp = a[i];
for(j=i-dk; ((j>=0) && (temp < a[j])); j -= dk)
{
a[j+dk] = a[j];
}
a[j+dk] = temp;
}
}
}

void ShellSort(int a[],const int p,const int r,const int dlta[],const int t)
{
//希尔排序算法-主程序
//按增量序列dlta[]中的前t个增量,实现对数组a[]中a[p]到a[r]的排序
//dlta[]可能取值如:1,2,3,5,9 dala[k]=2^(t-k+1)-1 其中0<=k<=t<=ld(b-1)
//增量序列的最后一个值必须是1
//增量序列中的值没有除1以外的因子, 其精确时间复杂度:数学上尚未解决的难题
int k;
for(k=0; k<t; k++)
{
ShellInsert(a,p,r,dlta[k]);
}
}

/************************堆排序***********************/
//堆排序,不如快速排序
//但是可用其来实现“优先级队列”
int Parent(int i)
{
return ((i+1)/2-1);
}

int Right(int i)
{
return (2*(i+1)-1);
}

int Left(int i)
{
return (2*(i+1));
}

void Max_Heapify(int a[],const int hplast,const int i)
{
int l, r,largest,temp;
l = Left(i);
r = Right(i);
largest = ((l<=hplast) && (a[l]>a[i])) ? l:i;
if((r<=hplast) && (a[r]>a[largest]))
{
largest = r;
}
if(largest != i)
{
temp = a[i];
a[i] = a[largest];
a[largest] = temp;
Max_Heapify(a,hplast,largest);
}

}

void Build_Max_Heap(int a[],const int p, const int r)
{
int i;
for(i = (p+r)/2; i>=p; i--)
{
Max_Heapify(a,r,i);
}
}

void HeapSort(int a[],const int p, int r)
{
int i,temp;
Build_Max_Heap(a,p,r);
for(i = r; i > p; i--)
{
temp = a[p];
a[p] = a[i];
a[i] = temp;
r -= 1;
Max_Heapify(a,r,0);
}
}

❷ Scratch儿童编程入门书籍都有哪些

我本身是程序员,我的孩子,还在小学2年级时,我就给她学习Scratch,半天时间,她就用我找的视频教程(网页链接),一起完成了一个打弹珠的游戏了。当然,视频上教的是其他动画角色,她改成了自己最喜欢的kitty猫作主角。

一开始就看书学理论,不太适合小学生,本来Scratch就很简单,图形化的编程界面,放手让孩子直接操作吧。当有需要进一步了解、深入学习时,再看理论。

就用小例子,先练着。

❸ dk3本编程书有什么区别

版本不同。
《DK编程教室》是2020年南海出版公司出版的图书。在美国、英国、日本和芬兰,编程已进入小学课堂,成为儿童教育的基础课程。在中国,编程已被北京、浙江、山东等多个省市纳入中小学课程体系,并将在全国逐步推广。DK编程真好玩:6岁开始学Scratch,书中主要是通过创作游戏来学习编程,没有基础的孩子可以一步步的跟学,逐渐的增加难度。内容形式很有趣,像我家孩子特别喜欢的红、黄、蓝球大战,从自己玩游戏到能自己尝试制作游戏,孩子自己也很高兴。
Scratch是一款由麻省理工学院(MIT)设计开发的面向少年儿童的简易编程工具,又称为积件式儿童编程软件,针对8岁以上孩子的认知水平,用类似于积木的模块实现构成程序的命令和参数。《DK编程玩起来。》系列从Scratch基础开始,难度逐步增加,让小朋友可以通过自学轻松入门,用Scratch的基本方法根据案例进行编程、制作简单小游戏,最终达到自己独立编程的水平。书中包含多个Scratch实战案例,趣味性与实用性兼顾,既提高了小朋友对Scratch编程的兴趣,又充分满足了学习编程的需要。让小朋友可以通过自学轻松入门,进而创建好玩儿的小游戏和小程序。

热点内容
开源库编译管理员 发布:2025-02-06 09:39:14 浏览:914
脸书怎么注册安卓 发布:2025-02-06 09:36:47 浏览:381
车用安卓导航无线打不开什么原因 发布:2025-02-06 09:27:50 浏览:790
安卓与苹果如何互相传送文件 发布:2025-02-06 09:27:40 浏览:26
华为服务器盘符如何分配 发布:2025-02-06 09:26:41 浏览:560
传奇h5源码下载 发布:2025-02-06 09:26:06 浏览:78
编译uclibc 发布:2025-02-06 09:09:04 浏览:152
用gcc编译16位汇编 发布:2025-02-06 09:06:07 浏览:823
什么低端安卓手机不卡 发布:2025-02-06 09:03:32 浏览:14
我的世界服务器卡领地 发布:2025-02-06 08:50:45 浏览:256