1,486
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
int comp(const void*a,const void*b)
{
return *(int*)a-*(int*)b;
}
int main()
{
int i=0;
int *array;
int n;
scanf("%d",&n);
array=(int*)malloc(n*sizeof(int));
for(;i<n;i++)
{
scanf("%d",(array+i));
}
qsort(array,n,sizeof(int),comp);
for(i=0;i<n;i++)
{
printf("%d\t",array[i]);
}
return 0;
}
Option Explicit
Private Sub Command1_Click()
Dim arrData() As Long
Dim i&, k As Long
Me.Cls
If (CreateQSort()) Then
Me.Print "接口对象创建失败。"
Else
Me.Print "接口对象创建成功。"
k = 15&
Call Randomize
ReDim arrData(k)
For i = 0& To k
arrData(i) = 5000& * Rnd()
Next
Call QuickSort(arrData(), 0&, k)
For i = 0& To k
Me.Print i; arrData(i)
Next
End If
End Sub
Private Sub Command2_Click()
Dim arrData() As Long
Dim fTime!, lNum&, i&
lNum = Val(Text1.Text)
If (5& > lNum) Then lNum = 5&
lNum = 10000& * lNum - 1&
Me.Cls
Call Randomize
Call CreateQSort
ReDim arrData(lNum)
DoEvents
fTime = Timer
For i = 0& To lNum
arrData(i) = &H3FFFFFF * Rnd()
Next
Me.Cls
Me.Print "数据总数: "; i \ 10000&; "万个"
Me.Print "产生数据耗时:"; Format$(Timer - fTime, "0.00") & "秒"
DoEvents
fTime = Timer
Call QuickSort(arrData(), 0&, lNum)
Me.Print "数据排序耗时:"; Format$(Timer - fTime, "0.00") & "秒"
End Sub
Private Declare Function qsort Lib "NTDLL.DLL" (base As Long, ByVal nelem As Long, ByVal width As Long, ByVal fcmp As Long) As Long
Private Declare Function atoi Lib "ntdll" (ByVal str As String) As Long '字符串转换到整型数
Private Declare Function sin1 Lib "ntdll" Alias "sin" (ByVal numn As Double) As Double 'sin
Private Sub Command1_Click()
Dim a As Long
Dim b As String
b = "123.456"
a = atoi(b)
MsgBox a
'----------------------
Dim c, d As Single
c = 1
d = sin1(c)
MsgBox d
End Sub
int comp(const void*a,const void*b)
{
return *(int*)a-*(int*)b;
}