数据结构实战——指针&栈
学以致用,采用堆栈head, rear指针的原理建立一个简单的列表用于存放分解的数据。符合需要方便插入不同长度数据的特征。
源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
Sub division() ' ' division 宏 ' ' row_0 = 2 '起始行 row_1 = 50 '终止行 col_00 = "A" '电话列 col_01 = "B" '金额列 col_10 = "D" '输出电话列 col_11 = "E" '输出金额列 '定义指针,该脚本采用链表结构 head = row_0 rear = row_0 - 1 For Row = row_0 To row_1 Num = Range(col_00 & CStr(Row)).Value Cost = Range(col_01 & CStr(Row)).Value If Cost > 200 Then If Cost Mod 200 = 0 Then Add_rows = Cost / 200 rear = head + Add_rows Else Add_rows = (Cost - 100) / 200 rear = head + Add_rows Range(col_10 & CStr(rear)).Value = Num Range(col_11 & CStr(rear)).Value = 100 rear = rear + 1 End If i = 0 While i < Add_rows Range(col_10 & CStr(head + i)).Value = Num Range(col_11 & CStr(head + i)).Value = 200 i = i + 1 Wend head = rear Else Range(col_10 & CStr(head)).Value = Num Range(col_11 & CStr(head)).Value = Cost rear = head + 1 head = rear End If Next Row End Sub |