2014年4月24日星期四
最近在学习数据结构,了解到的第一种很简单的数据结构是Bag,用数组来实现。
在真正实现的时候,我希望建一个类库项目来具体实现数据结构,为了一目了然,我把项目名取为Bag。在类库项目Bag下面,会有一个默认的类文件class1.cs。
这儿我将这个类文件给删除了,然后重新添加了一个,命名为Bag.cs的类文件。然后在Bag.cs里面写实现代码,右击项目名,选择“生成”,生产bag.dll文件。Bag.cs的实现代码如下:
// FILE://Bag.cs // CLASS IMPLMENT: class Bag // // CONSTRUCTORS for classBag // Bag(): // Postcondition: default constructor, generatean instance of the bag class // and the capacity of the bag class is 30 // // Bag(bag_size size): // Postcondition: generate an instance of thebag class, and the capacity is // decided by the parameter users provide // // MODIFICATION MEMBERMETHODS for class Bag // bool insert(bag_typemember): // Precondition: it's not beyond the capacityof the bag // Postcondition: if insert successfully returntrue, otherwise false // // bool erase(bag_typemember): // Postcondition: if erase successfully returntrue, otherwise false // // int search(bag_typetarget): // Postcondition: if find return the index,otherwise NOT_FOUND(equal -1) // // CONST MEMBER METHOD forbag class (not const now) // void travel(): // Postcondition: travel the bag // // int count(bag_typetarget): // Postcondition: return how many times thetarget has been found, if // not found, return 0 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; // Alias the data type withmy own type using bag_size = System.UInt32; using bag_type