求助:VB排序代码,小弟工作不保求助啊!

newnazi 2013-02-20 11:43:54
冒泡 选择 插入 快速 堆 希尔 归并 基数 外部 位图 拓补


最近 台湾来了个不懂技术的主管,不知怎么的最近经常说我;今天给我安排了一个
工作 用VB写排序,我还没问就把电话挂了所以我想把所有的排序都写了吧。

请求大虾帮忙啊~
...全文
1135 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
newnazi 2013-03-14
  • 打赏
  • 举报
回复
引用 12 楼 bcrun 的回复:
引用 11 楼 newnazi 的回复:已 经 搞 定 了 恭喜楼主,可以介绍一下经验,这坛子里肯定还有给台湾老板打工的.
面试是上机编程,其实都很简单不过适合刚出校门的学生
newnazi 2013-02-24
  • 打赏
  • 举报
回复
代码我贴 出来,用VB6写的 '''新建bas文件 Attribute VB_Name = "Module1" Option Explicit Global Const ZERO = 0 Global Const ASCENDING_ORDER = 0 Global Const DESCENDING_ORDER = 1 Global gIterations Sub BubbleSort(MyArray(), ByVal nOrder As Integer) Dim Index Dim TEMP Dim NextElement NextElement = ZERO Do While (NextElement < UBound(MyArray)) Index = UBound(MyArray) Do While (Index > NextElement) If nOrder = ASCENDING_ORDER Then If MyArray(Index) < MyArray(Index - 1) Then TEMP = MyArray(Index) MyArray(Index) = MyArray(Index - 1) MyArray(Index - 1) = TEMP End If ElseIf nOrder = DESCENDING_ORDER Then If MyArray(Index) >= MyArray(Index - 1) Then TEMP = MyArray(Index) MyArray(Index) = MyArray(Index - 1) MyArray(Index - 1) = TEMP End If End If Index = Index - 1 gIterations = gIterations + 1 Loop NextElement = NextElement + 1 gIterations = gIterations + 1 Loop End Sub Sub Bucket(MyArray(), ByVal nOrder As Integer) Dim Index Dim NextElement Dim TheBucket NextElement = LBound(MyArray) + 1 While (NextElement <= UBound(MyArray)) TheBucket = MyArray(NextElement) Index = NextElement Do If Index > LBound(MyArray) Then If nOrder = ASCENDING_ORDER Then If TheBucket < MyArray(Index - 1) Then MyArray(Index) = MyArray(Index - 1) Index = Index - 1 Else Exit Do End If ElseIf nOrder = DESCENDING_ORDER Then If TheBucket >= MyArray(Index - 1) Then MyArray(Index) = MyArray(Index - 1) Index = Index - 1 Else Exit Do End If End If Else Exit Do End If gIterations = gIterations + 1 Loop MyArray(Index) = TheBucket NextElement = NextElement + 1 gIterations = gIterations + 1 Wend End Sub ''堆排序 Sub Heap(MyArray()) Dim Index Dim Size Dim TEMP Size = UBound(MyArray) Index = 1 While (Index <= Size) Call HeapSiftup(MyArray(), Index) Index = Index + 1 gIterations = gIterations + 1 Wend Index = Size While (Index > 0) TEMP = MyArray(0) MyArray(0) = MyArray(Index) MyArray(Index) = TEMP Call HeapSiftdown(MyArray(), Index - 1) Index = Index - 1 gIterations = gIterations + 1 Wend End Sub Sub HeapSiftdown(MyArray(), M) Dim Index Dim Parent Dim TEMP Index = 0 Parent = 2 * Index Do While (Parent <= M) If (Parent < M And MyArray(Parent) < MyArray(Parent + 1)) Then Parent = Parent + 1 End If If MyArray(Index) >= MyArray(Parent) Then Exit Do End If TEMP = MyArray(Index) MyArray(Index) = MyArray(Parent) MyArray(Parent) = TEMP Index = Parent Parent = 2 * Index gIterations = gIterations + 1 Loop End Sub Sub HeapSiftup(MyArray(), M) Dim Index Dim Parent Dim TEMP Index = M Do While (Index > 0) Parent = Int(Index / 2) If MyArray(Parent) >= MyArray(Index) Then Exit Do End If TEMP = MyArray(Index) MyArray(Index) = MyArray(Parent) MyArray(Parent) = TEMP Index = Parent gIterations = gIterations + 1 Loop End Sub Sub Insertion(MyArray(), ByVal nOrder As Integer) Dim Index Dim TEMP Dim NextElement NextElement = LBound(MyArray) + 1 While (NextElement <= UBound(MyArray)) Index = NextElement Do If Index > LBound(MyArray) Then If nOrder = ASCENDING_ORDER Then If MyArray(Index) < MyArray(Index - 1) Then TEMP = MyArray(Index) MyArray(Index) = MyArray(Index - 1) MyArray(Index - 1) = TEMP Index = Index - 1 Else Exit Do End If ElseIf nOrder = DESCENDING_ORDER Then If MyArray(Index) >= MyArray(Index - 1) Then TEMP = MyArray(Index) MyArray(Index) = MyArray(Index - 1) MyArray(Index - 1) = TEMP Index = Index - 1 Else Exit Do End If End If Else Exit Do End If gIterations = gIterations + 1 Loop NextElement = NextElement + 1 gIterations = gIterations + 1 Wend End Sub Sub QuickSort(MyArray(), L, R) Dim I, J, X, Y I = L J = R X = MyArray((L + R) / 2) While (I <= J) While (MyArray(I) < X And I < R) I = I + 1 Wend While (X < MyArray(J) And J > L) J = J - 1 Wend If (I <= J) Then Y = MyArray(I) MyArray(I) = MyArray(J) MyArray(J) = Y I = I + 1 J = J - 1 End If gIterations = gIterations + 1 Wend If (L < J) Then Call QuickSort(MyArray(), L, J) If (I < R) Then Call QuickSort(MyArray(), I, R) End Sub Sub Selection(MyArray(), ByVal nOrder As Integer) Dim Index Dim Min Dim NextElement Dim TEMP NextElement = 0 While (NextElement < UBound(MyArray)) Min = UBound(MyArray) Index = Min - 1 While (Index >= NextElement) If nOrder = ASCENDING_ORDER Then If MyArray(Index) < MyArray(Min) Then Min = Index End If ElseIf nOrder = DESCENDING_ORDER Then If MyArray(Index) >= MyArray(Min) Then Min = Index End If End If Index = Index - 1 gIterations = gIterations + 1 Wend TEMP = MyArray(Min) MyArray(Min) = MyArray(NextElement) MyArray(NextElement) = TEMP NextElement = NextElement + 1 gIterations = gIterations - 1 Wend End Sub Sub ShellSort(MyArray(), ByVal nOrder As Integer) Dim Distance Dim Size Dim Index Dim NextElement Dim TEMP Size = UBound(MyArray) - LBound(MyArray) + 1 Distance = 1 While (Distance <= Size) Distance = 2 * Distance Wend Distance = (Distance / 2) - 1 While (Distance > 0) NextElement = LBound(MyArray) + Distance While (NextElement <= UBound(MyArray)) Index = NextElement Do If Index >= (LBound(MyArray) + Distance) Then If nOrder = ASCENDING_ORDER Then If MyArray(Index) < MyArray(Index - Distance) Then TEMP = MyArray(Index) MyArray(Index) = MyArray(Index - Distance) MyArray(Index - Distance) = TEMP Index = Index - Distance gIterations = gIterations + 1 Else Exit Do End If ElseIf nOrder = DESCENDING_ORDER Then If MyArray(Index) >= MyArray(Index - Distance) Then TEMP = MyArray(Index) MyArray(Index) = MyArray(Index - Distance) MyArray(Index - Distance) = TEMP Index = Index - Distance gIterations = gIterations + 1 Else Exit Do End If End If Else Exit Do End If Loop NextElement = NextElement + 1 gIterations = gIterations + 1 Wend Distance = (Distance - 1) / 2 gIterations = gIterations + 1 Wend End Sub
bcrun 2013-02-23
  • 打赏
  • 举报
回复
引用 11 楼 newnazi 的回复:
已 经 搞 定 了
恭喜楼主,可以介绍一下经验,这坛子里肯定还有给台湾老板打工的.
lliai 2013-02-22
  • 打赏
  • 举报
回复
很多算法,看数据量了。的问清楚。
newnazi 2013-02-22
  • 打赏
  • 举报
回复
已 经 搞 定 了
橘子皮... 2013-02-22
  • 打赏
  • 举报
回复
排序还要写吗?网上一大堆啊
threenewbee 2013-02-21
  • 打赏
  • 举报
回复
引用 7 楼 newnazi 的回复:
二叉排序的谁能给个例子 代码?
没有什么“二叉”排序,估计是在说堆排序的一种黑话——堆排序使用了二叉树。
  • 打赏
  • 举报
回复
还是打电话问清楚吧,这样糊里糊涂的做了 到时要是不对,你浪费的时间只能得到一句:不清楚当时怎么不问???
newnazi 2013-02-21
  • 打赏
  • 举报
回复
二叉排序的谁能给个例子 代码?
bcrun 2013-02-21
  • 打赏
  • 举报
回复
汗,你就这样迷糊着干活啊,那搜点排序算法的资料应付吧
newnazi 2013-02-21
  • 打赏
  • 举报
回复
引用 5 楼 caozhy 的回复:
我建议你们不好沟通的时候就用英文。
已经去南方了,估计是深圳吧,
threenewbee 2013-02-21
  • 打赏
  • 举报
回复
我建议你们不好沟通的时候就用英文。
threenewbee 2013-02-21
  • 打赏
  • 举报
回复
台湾人本来用的术语就和大陆不同,发音有很怪异。那这个差别太大了,搞不好就是鸡同鸭讲。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧