private static void PrintUsers(IIterator iterate) { while (!iterate.IsDone()) { Console.WriteLine(iterate.Next()); } }
public static void PrintUsers(IIterator iterate) { iterate.First(); while (!iterate.IsDone()) { Console.WriteLine(iterate.Next()); } }
public void printMember(IIterator iterate) { iterate.First(); while (!iterate.IsDone()) { //textBox.AppendText("Friend"); } }
private void SearchStudent() { Console.WriteLine("Enter the name of the student to search:"); string keyword = Console.ReadLine(); IIterator iterator = studentList.createIterator(); while (!iterator.IsDone()) { if (iterator.CurrentItem().Name.IndexOf(keyword, StringComparison.Ordinal) > -1) { Console.WriteLine(iterator.CurrentItem().Display()); } iterator.Next(); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
Image CreatePreviewImage(string r, char key) { int height = 80; int width = 530; int space = 2; int size = 29; int leftSpan = 5; int topSpan = 5; ArrayList squareArray = new ArrayList(); IGlyph glyph; glyph = new Square(leftSpan, topSpan + size + 2, size, Color.HotPink, GlyphAppearance.Flat, "?"); squareArray.Add(glyph); for (int i = 0; i < r.Length; i++) { glyph = new Square(leftSpan + (i + 1) * (size + space), topSpan + size + 2, size, Color.Teal, GlyphAppearance.Flat, r[i].ToString()); squareArray.Add(glyph); } squareLine = new SquareLine(0, 0, 1, squareArray); //最后初始化所有的迭代器 IIterator arrayIterator = squareLine.CreateIterator(); IIterator nullIterator = null; glyph = ((ArrayIterator)arrayIterator).GetGlyphByIndex((r.Length + 1) / 2); if (glyph != null) { nullIterator = new Square(glyph.Bounds.X, glyph.Bounds.Y - size - 2, size, Color.Red, GlyphAppearance.Flat, key.ToString()).CreateIterator(); } Bitmap bmp = new Bitmap(width, height); Graphics g = Graphics.FromImage(bmp); for (IIterator iterator = arrayIterator.First(); !arrayIterator.IsDone(); iterator = arrayIterator.Next()) { iterator.CurrentItem.Draw(g); } if (nullIterator != null) { nullIterator.CurrentItem.Draw(g); } return(bmp); }
private void SearchLecturer() { Console.WriteLine("Input search text:"); string keyword = Console.ReadLine(); IIterator iterator = lecturerList.createIterator(); while (!iterator.IsDone()) { if (iterator.CurrentItem().Name.IndexOf(keyword, StringComparison.Ordinal) > -1) { Console.WriteLine(iterator.CurrentItem().Display()); } iterator.Next(); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public IEnumerable <Route> Solve(IGraphDatabase graph, City from, City to) { Dictionary <City, Route> routes = new Dictionary <City, Route>(); routes[from] = null; Stack <City> stack = new Stack <City>(); stack.Push(from); do { City city = stack.Pop(); IIterator <Route> iterator = graph.GetRoutesFrom(city); while (!iterator.IsDone()) { Route route = iterator.GetNext(); if (route == null) { continue; } if (routes.ContainsKey(route.To)) { continue; } routes[route.To] = route; if (route.To == to) { break; } stack.Push(route.To); } } while (stack.Count > 0); if (!routes.ContainsKey(to)) { return(null); } List <Route> result = new List <Route>(); for (Route route = routes[to]; route != null; route = routes[route.From]) { result.Add(route); } result.Reverse(); return(result); }
Image CreatePreviewImage(string r) { int width = 530; int startX = 10; int maxHeight = 145; int heightUnit; int histogramWidth = 20; int histogramSpace = 15; int bottomY = 30; heightUnit = (maxHeight - bottomY - 15) / r.Length; int height = 0; ArrayList squareArray = new ArrayList(); IGlyph glyph; glyph = new MyRectangle(startX, maxHeight - bottomY - 45, histogramWidth, 45, Color.Gold, GlyphAppearance.Popup, "?"); squareArray.Add(glyph); for (int i = 0; i < r.Length; i++) { height = GetHeight(r, i, heightUnit); glyph = new MyRectangle(startX + (i + 1) * (histogramWidth + histogramSpace), maxHeight - bottomY - height, histogramWidth, height, Color.HotPink, GlyphAppearance.Popup, r[i].ToString()); squareArray.Add(glyph); } squareLine = new SquareLine(1, 1, 1, squareArray); //最后初始化所有的迭代器 IIterator arrayIterator = squareLine.CreateIterator(); Bitmap bmp = new Bitmap(width, maxHeight); Graphics g = Graphics.FromImage(bmp); if (arrayIterator != null) { for (IIterator iterator = arrayIterator.First(); !arrayIterator.IsDone(); iterator = arrayIterator.Next()) { iterator.CurrentItem.Draw(g); } } return(bmp); }
public override void UpdateAnimationPad() { base.UpdateAnimationPad(); Graphics g = AlgorithmManager.Algorithms.ClearAnimationPad(); if (AlgorithmManager.Algorithms.CurrentAlgorithm != null) { if (arrayIterator != null) { for (IIterator iterator = arrayIterator.First(); !arrayIterator.IsDone(); iterator = arrayIterator.Next()) { iterator.CurrentItem.Draw(g); } } if (nullIterator != null) { nullIterator.CurrentItem.Draw(g); } } }
static void Main(string[] args) { ConcreteAgregate agregate = new ConcreteAgregate(); agregate.Add("Marcin"); agregate.Add("Tomasz"); agregate.Add("Paweł"); agregate.Add("Krzysztof"); agregate.Add("Piotr"); IIterator iterator = agregate.GetIterator(); while (!iterator.IsDone()) { Console.WriteLine(iterator.CurrentItem()); iterator.Next(); } }
private void ShowStatistics(Foi foi) { Output output = Output.GetInstance(); IIterator placeIterator = foi.Places.CreateIterator(IteratorType.Sequential); for ( Place place = (Place)placeIterator.First(); !placeIterator.IsDone(); place = (Place)placeIterator.Next() ) { output.WriteLine(place.ToString()); output.WriteLine(">>>>>>>>>>>>>>> > UREĐAJI < <<<<<<<<<<<<<<<<<\r\n"); foreach (var device in place.Devices) { output.WriteLine(device.ToString()); } } }
private void SaveSettingsToFile() { using (FileStream fs = File.Open("settings.dat", FileMode.Create)) { try { using (BinaryWriter w = new BinaryWriter(fs)) { w.Write(settings.StepDelay); w.Write(settings.RetryStepDelay); w.Write(settings.MaximumNumberOfRetries); int rowsCount = instance.GetMatrixRowCount(); int columnsCount = instance.GetMatrixColumnCount(); w.Write(rowsCount); w.Write(columnsCount); w.Write(settings.RowDeviation); w.Write(settings.ColumnDeviation); IIterator instanceIterator = instance.Iterator(); instanceIterator.First(); while (!instanceIterator.IsDone()) { ExportPointMatrixItem item = instanceIterator.CurrentItem(); w.Write(item.PointDescription); w.Write(item.IsAvaliable); instanceIterator.Next(); } w.Close(); } #if DEBUG Console.WriteLine("写入文件完成"); #endif } catch (IOException e) { #if DEBUG Console.WriteLine("写入文件发生 IO 错误: " + e.Message); #endif } } }
public override void UpdateAnimationPad() { base.UpdateAnimationPad(); Graphics g = AlgorithmManager.Algorithms.ClearAnimationPad(); if (AlgorithmManager.Algorithms.CurrentAlgorithm != null) { if (circleNodeIterator != null) { for (IIterator iterator = circleNodeIterator.First(); !circleNodeIterator.IsDone(); iterator = circleNodeIterator.Next()) { iterator.CurrentItem.Draw(g); } } if (lineNodeIterator != null) { for (IIterator iterator = lineNodeIterator.First(); !lineNodeIterator.IsDone(); iterator = lineNodeIterator.Next()) { iterator.CurrentItem.Draw(g); } } if (nullIteratorP != null) { nullIteratorP.CurrentItem.Draw(g); } if (nullIteratorS != null) { nullIteratorS.CurrentItem.Draw(g); } if (iteratorInsertNode != null) { iteratorInsertNode.First().CurrentItem.Draw(g); } if (nullIteratorBezierLine != null) { nullIteratorBezierLine.CurrentItem.Draw(g); } } }
public void Start() { ConcreteAggregate a = new ConcreteAggregate(); a[0] = "First element"; a[1] = "Second element"; a[2] = "Third element"; IIterator i = a.CreateIterator(); Console.WriteLine("Collection is:"); object item = i.First(); while (item != null) { Console.WriteLine($"- {item}"); item = i.Next(); } Console.WriteLine($"\nCurrent item: {i.CurrentItem()}"); Console.WriteLine($"Is done: {i.IsDone()}"); }
Image CreatePreviewImage(string s, int pos) { int height = 80; int width = 530; int space = 2; int size = 35; int leftSpan = 15; int topSpan = 20; ArrayList squareArray = new ArrayList(); IGlyph glyph; for (int i = 0; i < s.Length; i++) { if (pos - 1 != i) { glyph = new Square(leftSpan + i * (size + space), topSpan, size, Color.DarkCyan, GlyphAppearance.Flat, s[i].ToString()); } else //用红色表示要删除的元素 { glyph = new Square(leftSpan + i * (size + space), topSpan, size, Color.Red, GlyphAppearance.Flat, s[i].ToString()); } squareArray.Add(glyph); } squareLine = new SquareLine(1, 1, 1, squareArray); IIterator arrayIterator = squareLine.CreateIterator(); Bitmap bmp = new Bitmap(width, height); Graphics g = Graphics.FromImage(bmp); for (IIterator iterator = arrayIterator.First(); !arrayIterator.IsDone(); iterator = arrayIterator.Next()) { iterator.CurrentItem.Draw(g); } return(bmp); }
static void Main(string[] args) { object[] arr = { "1", "2", "3", "4", "5", "6" }; var aggrate = new ConcreteAggrate(arr); Console.WriteLine("this is for loop!"); for (var i = 0; i < aggrate.GetSize(); i++) { Console.WriteLine(aggrate.GetElement(i)); } Console.WriteLine("this is iterator loop!"); IIterator iterator = aggrate.GetIterator(); while (!iterator.IsDone()) { Console.WriteLine(iterator.GetElement()); iterator.MoveNext() ; } Console.ReadLine(); }
private void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked) { while (!hrIterator.IsDone()) { listBox1.Items.Add(hrIterator.Next()); } } else if (radioButton2.Checked) { while (!itIterator.IsDone()) { listBox1.Items.Add(itIterator.Next()); } } else if (radioButton3.Checked) { while (!mnIterator.IsDone()) { listBox1.Items.Add(mnIterator.Next()); } } }
public bool IsDone() { return(_myIt.IsDone()); }
public static List <IProcessItem> GenerateProcessQueue( ExportPointMatrix matrix, TargetRectangle rectangle, WindowHandle handle, SettingComponent settings) { List <IProcessItem> queue = new List <IProcessItem>(); IProcessItem procItem; switch (settings.ProcessType) { case ProcessTypeFlags.MAINBOARD_FIND_HANDLE: procItem = new ProcessItem_FindWindowByName(handle, settings.SearchTitle, 0, false); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); break; case ProcessTypeFlags.MAINBOARD_FIND_RECTANGLE: procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Plate 1", 0); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "GXWND", 1); queue.Add(procItem); procItem = new ProcessItem_GetControlRectangle(handle); queue.Add(procItem); procItem = new ProcessItem_CalcRectExportPointMatrix(matrix, rectangle, settings.RowDeviation, settings.ColumnDeviation); queue.Add(procItem); break; case ProcessTypeFlags.MAINBOARD_CHECK_POSITION: { IIterator matrixPointIterator = matrix.Iterator(); for (; !matrixPointIterator.IsDone(); matrixPointIterator.Next()) { ExportPointMatrixItem item = matrixPointIterator.CurrentItem(); if (!item.IsAvaliable) { continue; // 没被选中忽略 } else { procItem = new ProcessItem_MouseMove(item.PointX, item.PointY); queue.Add(procItem); } } } break; case ProcessTypeFlags.OVERWRITE_PARENT_WND: procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); break; case ProcessTypeFlags.FIND_WINDOW: procItem = new ProcessItem_FindWindow(handle, settings.StringParam); queue.Add(procItem); break; case ProcessTypeFlags.FIND_WINDOW_EX: procItem = new ProcessItem_FindWindowEx(handle, settings.StringParam); queue.Add(procItem); break; case ProcessTypeFlags.FIND_WINDOW_BY_NAME: procItem = new ProcessItem_FindWindowByName(handle, settings.StringParam, settings.IntParam, false); queue.Add(procItem); break; case ProcessTypeFlags.FIND_CONTROL_BY_CLASSNAME: procItem = new ProcessItem_FindCtrlByCtrlClass(handle, settings.StringParam, settings.IntParam); queue.Add(procItem); break; case ProcessTypeFlags.FIND_CONTROL_BY_NAME: procItem = new ProcessItem_FindCtrlByCtrlName(handle, settings.StringParam, settings.IntParam); queue.Add(procItem); break; case ProcessTypeFlags.GET_WINDOW_RECTANGLE: procItem = new ProcessItem_GetControlRectangle(handle); queue.Add(procItem); break; case ProcessTypeFlags.CALCULATE_RECTANGLE_EXPORT_POINT_MATRIX: procItem = new ProcessItem_CalcRectExportPointMatrix(matrix, rectangle, settings.RowDeviation, settings.RowDeviation); queue.Add(procItem); break; case ProcessTypeFlags.SET_COMBOBOX_CURSEL: procItem = new ProcessItem_SetComboBoxCrusel(handle, settings.IntParam); queue.Add(procItem); break; case ProcessTypeFlags.SET_TEXTBOX_VALUE: procItem = new ProcessItem_SetTextBoxValue(handle, settings.StringParam); queue.Add(procItem); break; case ProcessTypeFlags.CONTROL_MOUSE_LBUTTON_CLICK: procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); break; case ProcessTypeFlags.MOUSE_LBUTTON_CLICK: procItem = new ProcessItem_NormMouseLeftButtonClick(); queue.Add(procItem); break; case ProcessTypeFlags.DEFAULT: { IIterator matrixPointIterator = matrix.Iterator(); for (; !matrixPointIterator.IsDone(); matrixPointIterator.Next()) { ExportPointMatrixItem item = matrixPointIterator.CurrentItem(); // 判断该位置是否被选中 if (!item.IsAvaliable) { continue; // 没被选中忽略 } else // 开始执行既定步骤 { // 鼠标移动到该位置 procItem = new ProcessItem_MouseMove(item.PointX, item.PointY); queue.Add(procItem); // 鼠标点击该位置 procItem = new ProcessItem_NormMouseLeftButtonClick(); queue.Add(procItem); /* 弹出图片详情后 */ // 获取主窗口句柄 procItem = new ProcessItem_FindWindowByName(handle, settings.SearchTitle, 0, true); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); // 找到 Plate 1 控件句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Plate 1", 0); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); // 找到 Process... 按钮句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Process...", 0); queue.Add(procItem); // 点击 Process 按钮 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); /* 弹出 Image Stitching 后 */ // 获取 Image Stitching 窗口句柄 procItem = new ProcessItem_FindWindowByName(handle, "Image Stitching", 0, true); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); // 获取 ComboBox 句柄 procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "ComboBox", 0); queue.Add(procItem); // 设置 ComboBox 选项为第 1 个 procItem = new ProcessItem_SetComboBoxCrusel(handle, 0); queue.Add(procItem); // 获取 Edit 句柄 procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "Edit", 0); queue.Add(procItem); // 设置 Edit 值为 50.00 procItem = new ProcessItem_SetTextBoxValue(handle, "50.00"); queue.Add(procItem); // 获取 OK 按钮句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "OK", 0); queue.Add(procItem); // 点击 OK 按钮 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); /* 弹出 Image Processing 窗口后 */ for (int i = 0; i < 3; i++) { // 找到 Image Processing 窗口句柄 procItem = new ProcessItem_FindWindowByName(handle, "Image Processing", 0, true); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); // 分别选择不同选项 switch (i) { case 0: // DAPI + GFP, 无需操作复选框 break; case 1: // DAPI, 取消选中 GFP // 获取 GFP 复选框句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Stitched[GFP 469,525]", 0); queue.Add(procItem); // 点击 GFP 按钮 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); break; case 2: // GFP, 取消选中 DAPI // 获取 DAPI 复选框句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Stitched[DAPI 377,447]", 0); queue.Add(procItem); // 点击 DAPI 复选框 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); // 获取 GFP 复选框句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Stitched[GFP 469,525]", 0); queue.Add(procItem); // 点击 GFP 复选框 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); break; } // 获取 Save Image Set 按钮句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Save Image Set", 0); queue.Add(procItem); // 点击 Save Image Set 按钮 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); /* 弹出 Image Save Options 窗口后 */ // 获取 Save Image Options 窗口句柄 procItem = new ProcessItem_FindWindowByName(handle, "Image Save Options", 0, true); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); // 获取 Save picture for presentation 单选框句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Save picture for presentation", 0); queue.Add(procItem); // 点击 Save picture for presentation 单选框 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); // 获取 Save entire image (1 camera pixel resolution) 单选框句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Save entire image (1 camera pixel resolution)", 0); queue.Add(procItem); // 点击 Save entire image (1 camera pixel resolution) 单选框 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); // 获取 OK 按钮句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "OK", 0); queue.Add(procItem); // 点击 OK 按钮 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); /* 弹出 Save As Picture 窗口后 */ // 获取 Save As Picture 窗口句柄 procItem = new ProcessItem_FindWindowByName(handle, "Save As Picture", 0, false); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); // 获取文件名输入框 // 获取文件名输入框的句柄 procItem = new ProcessItem_FindCtrlByCtrlClass(handle, "Edit", 0); queue.Add(procItem); // 设置文件名(eg. ExpHlp_Expo_PosA1_DAPI_GFP_2017100112) StringBuilder sb = new StringBuilder(); sb.AppendFormat("ExpHlp_Expo_Pos{0}_", item.PointDescription); switch (i) { case 0: // DAPI + GFP sb.Append("DAPI_GFP_"); break; case 1: // DAPI sb.Append("DAPI_"); break; case 2: // GFP sb.Append("GFP_"); break; } sb.Append(DateTime.Now.ToString("yyyyMMddHHmm")); procItem = new ProcessItem_SetTextBoxValue(handle, sb.ToString()); queue.Add(procItem); // 获取 保存 按钮的句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "保存", 0); queue.Add(procItem); // 点击 保存 按钮 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); } /* 执行完成 Image Processing 窗口操作后 */ // 找到 Image Processing 窗口句柄 procItem = new ProcessItem_FindWindowByName(handle, "Image Processing", 0, true); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); // 获取 Close 按钮句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Close", 0); queue.Add(procItem); // 点击 Close 按钮 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); // 获取主窗口句柄 procItem = new ProcessItem_FindWindowByName(handle, settings.SearchTitle, 0, true); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); // 获取 Plate 1 控件句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Plate 1", 0); queue.Add(procItem); procItem = new ProcessItem_OverwriteCurrHndl2PrntHndl(handle); queue.Add(procItem); // 获取 Close 按钮句柄 procItem = new ProcessItem_FindCtrlByCtrlName(handle, "Close", 1); queue.Add(procItem); // 点击 Close 按钮 procItem = new ProcessItem_CtrlMouseLeftButtonClick(handle); queue.Add(procItem); } } } break; } return(queue); }
public IEnumerable <Route> Solve(IGraphDatabase graph, City from, City to) { Dictionary <City, (double dist, Route last)> distances = new Dictionary <City, (double dist, Route last)>(); HashSet <City> visitedCitites = new HashSet <City>(); distances[from] = (0, null); City minCity = from; while (minCity != to) { IIterator <Route> iterator = graph.GetRoutesFrom(minCity); while (!iterator.IsDone()) { Route route = iterator.GetNext(); if (route == null) { continue; } if (visitedCitites.Contains(route.To)) { continue; } double dist = distances[minCity].dist + OptimizingValueFunc(route); if (!distances.ContainsKey(route.To)) { distances[route.To] = (dist, route); } else { if (dist < distances[route.To].dist) { distances[route.To] = (dist, route); } } } visitedCitites.Add(minCity); minCity = null; foreach (var(city, (dist, route)) in distances) { if (visitedCitites.Contains(city)) { continue; } if (minCity == null || dist < distances[city].dist) { minCity = city; } } if (minCity == null) { return(null); } } List <Route> result = new List <Route>(); for (Route route = distances[to].last; route != null; route = distances[route.From].last) { result.Add(route); } result.Reverse(); return(result); }
/* * Method: EvaluateStack() * Purpose: Evaluate a stack from [0] - [2] (3 elements) * Parameters: HeavyObjectList * Returns: double */ public double EvaluateStack(HeavyObjectList input) { //look at the volume of each box List <float> volume = new List <float>(); for (IIterator i = input.CreateIterator(); !i.IsDone(); i.Next()) { volume.Add(i.CurrentItem().Volume); } volume.Sort(); volume.Reverse(); //by reversing after sort we can indicate that we want the most volume at the bottom to create that Pyramid shape. //test to see if the highest volume, (largest shape) is at the bottom (similar to the bottomweight except were not looking at mass if (volume[0] == input.At(0).Volume) { //now we can test to see if the rest if equal //because I know there are three objects in each list. int counter = 0; bool isSame = false; foreach (float vol in volume) { if (vol == input.At(counter).Volume) { counter++; isSame = true; continue; } else { isSame = false; break; //if the second volumes are not the same to volume stack (which should represent a Pyramid ) } } if (isSame) { //return a value based on the volume of each box float total = 0; foreach (float vol in volume) { total = total + vol; } float count = total / (input.Length() + 10); //similar to the bottom stack except were using the volume of each box count = (float)Math.Round(count); return(count); } else { //because it isnt the same (large, meduim,small) //we must have (large,small,medium) which isnt Pyramid itself float total = 0; foreach (float vol in volume) { total = total + vol; } float count = total / (input.Length() + 20); //similar to the bottom stack except were using the volume of each box count = (float)Math.Round(count); return(count); } } //the second largest box is now one the bottom else if (volume[1] == input.At(0).Volume) { //the largest box is now in the middle or top //lets check where the largest box is float largeBox = input.At(1).Volume; //check ot see if this is the largest box if (largeBox == volume[0]) //should be teh largest box (medium, large, small) { float total = 0; foreach (float vol in volume) { total = total + vol; } float count = total / (input.Length() + 30); //similar to the bottom stack except were using the volume of each box count = (float)Math.Round(count); return(count); } else //the largest is on the top, medium,small,large { float total = 0; foreach (float vol in volume) { total = total + vol; } float count = total / (input.Length() + 40); //similar to the bottom stack except were using the volume of each box count = (float)Math.Round(count); return(count); } } //smallest box is on the bottom else { //where is the largest back then //in the middle (small,large,medium) //check ot see if this is the largest box if (volume[0] == input.At(1).Volume) { float total = 0; foreach (float vol in volume) { total = total + vol; } float count = total / (input.Length() + 50); //similar to the bottom stack except were using the volume of each box count = (float)Math.Round(count); return(count); } else //the largest is on the top, (small,meduim,large) { float total = 0; foreach (float vol in volume) { total = total + vol; } float count = total / (input.Length() + 60); //similar to the bottom stack except were using the volume of each box count = (float)Math.Round(count); return(count); } } }
public override void UpdateAnimationPad() { Graphics g = AlgorithmManager.Algorithms.ClearAnimationPad(); Graphics g1 = AlgorithmManager.Algorithms.ClearStackPad(); IPadContent stackPad = WorkbenchSingleton.Workbench.GetPad(typeof(NetFocus.DataStructure.Gui.Pads.StackPad)); if (stackPad != null && stackIterator != null) { ((StackIterator)stackIterator).RefreshItems(stackPad.Control.Width - 6, stackPad.Control.Height - 1); } if (AlgorithmManager.Algorithms.CurrentAlgorithm != null) { if (preOrderTreeIterator != null) { for (IIterator iterator = preOrderTreeIterator.First(); !preOrderTreeIterator.IsDone(); iterator = preOrderTreeIterator.Next()) { if (iterator.CurrentItem != null) { iterator.CurrentItem.BackColor = status.结点颜色; iterator.CurrentItem.Draw(g); } } } if (preOrderTreeIterator1 != null) { for (IIterator iterator = preOrderTreeIterator1.First(); !preOrderTreeIterator1.IsDone(); iterator = preOrderTreeIterator1.Next()) { if (iterator.CurrentItem != null) { iterator.CurrentItem.Draw(g); } } } if (currentIterator != null) { if (currentIterator.CurrentItem != null) { if (visiting == false) { currentIterator.CurrentItem.BackColor = status.当前结点颜色; } else { currentIterator.CurrentItem.BackColor = status.输出结点颜色; } currentIterator.CurrentItem.Draw(g); } } if (stackIterator != null) { for (IIterator iterator = stackIterator.First(); !stackIterator.IsDone(); iterator = stackIterator.Next()) { if (iterator.CurrentItem != null) { iterator.CurrentItem.Draw(g1); } } } if (visitedIterator != null) { for (IIterator iterator = visitedIterator.First(); !visitedIterator.IsDone(); iterator = visitedIterator.Next()) { if (iterator.CurrentItem != null) { iterator.CurrentItem.Draw(g); } } } } }
Image CreatePreviewImage(string s, int pos, char e) { int height = 80; int width = 530; int lineLength = 18; int diameter = 30; int leftSpan = 3; int topSpan = 20; IIterator circleNodeIterator; //用于输出结点链表的指针 IIterator lineNodeIterator; //用于输出连接线链表的指针 LinkCircleNode headNode = null; LinkLineNode headLineNode = null; LinkCircleNode previousNode = null; LinkLineNode previousLineNode = null; LinkCircleNode currentNode = null; LinkLineNode currentLineNode = null; previousNode = headNode = new LinkCircleNode(leftSpan, topSpan, diameter, Color.Red, "H"); previousLineNode = headLineNode = new LinkLineNode(leftSpan + diameter, topSpan + diameter / 2, leftSpan + diameter + lineLength, topSpan + diameter / 2, lineWidth, Color.Red); s = s.Insert(pos - 1, e.ToString()); for (int i = 0; i < s.Length; i++) { if (i != pos - 1) { currentNode = new LinkCircleNode(leftSpan + (i + 1) * (lineLength + diameter), topSpan, diameter, Color.DarkTurquoise, s[i].ToString()); } else { currentNode = new LinkCircleNode(leftSpan + (i + 1) * (lineLength + diameter), topSpan, diameter, Color.DarkOrange, s[i].ToString()); } currentLineNode = new LinkLineNode(leftSpan + diameter + (i + 1) * (lineLength + diameter), topSpan + diameter / 2, leftSpan + diameter + (i + 1) * (lineLength + diameter) + lineLength, topSpan + diameter / 2, lineWidth, Color.Red); previousNode.Next = currentNode; previousLineNode.Next = currentLineNode; previousNode = currentNode; previousLineNode = currentLineNode; } currentNode.Next = null; currentLineNode.Next = null; circleNodeIterator = headNode.CreateIterator(); lineNodeIterator = headLineNode.CreateIterator(); Bitmap bmp = new Bitmap(width, height); Graphics g = Graphics.FromImage(bmp); if (circleNodeIterator != null) { for (IIterator iterator = circleNodeIterator.First(); !circleNodeIterator.IsDone(); iterator = circleNodeIterator.Next()) { iterator.CurrentItem.Draw(g); } } if (lineNodeIterator != null) { for (IIterator iterator = lineNodeIterator.First(); !lineNodeIterator.IsDone(); iterator = lineNodeIterator.Next()) { iterator.CurrentItem.Draw(g); } } return(bmp); }
static void Main(string[] args) { // Create our HeavyObjects (DO NOT MODIFY THESE VALUES) HeavyObject lightest = new HeavyObject(10, 10, 1, 1); HeavyObject medium = new HeavyObject(7, 7, 2, 5); HeavyObject heavyAndSmall = new HeavyObject(5, 5, 5, 50); // Create lists of the HeavyObjects and print them for debug purposes HeavyObjectList listA = new HeavyObjectList(); listA.Add(heavyAndSmall); listA.Add(medium); listA.Add(lightest); Console.WriteLine($"Testing First() method in ListA:"); IIterator iterator = listA.CreateIterator(); iterator.First().Print(); Console.WriteLine("\nItems in ListA:"); for (IIterator i = listA.CreateIterator(); !i.IsDone(); i.Next()) { i.CurrentItem().Print(); } Console.WriteLine(); HeavyObjectList listB = new HeavyObjectList(); listB.Add(medium); listB.Add(lightest); listB.Add(heavyAndSmall); iterator = listB.CreateIterator(); Console.WriteLine($"Testing First() method in ListB:"); iterator.First().Print(); Console.WriteLine("\nItems in ListB:"); for (IIterator i = listB.CreateIterator(); !i.IsDone(); i.Next()) { i.CurrentItem().Print(); } Console.WriteLine(); HeavyObjectList listC = new HeavyObjectList(); listC.Add(lightest); listC.Add(medium); listC.Add(heavyAndSmall); iterator = listC.CreateIterator(); Console.WriteLine($"Testing First() method in listC."); iterator.First().Print(); Console.WriteLine("\nItems in ListC:"); for (IIterator i = listC.CreateIterator(); !i.IsDone(); i.Next()) { i.CurrentItem().Print(); } Console.WriteLine(); // Create our Flyweight Factory and create the Flyweights out of it FlyweightFactory fw = new FlyweightFactory(); StackingStrategy bottomWeight = fw.GetFlyweight("bottomWeight"); StackingStrategy pyramid = fw.GetFlyweight("pyramid"); StackingStrategy topple = fw.GetFlyweight("topple"); // Print results Console.WriteLine("BottomWeight - ListA: " + bottomWeight.EvaluateStack(listA)); Console.WriteLine("BottomWeight - ListB: " + bottomWeight.EvaluateStack(listB)); Console.WriteLine("BottomWeight - ListC: " + bottomWeight.EvaluateStack(listC)); Console.WriteLine(); Console.WriteLine("Pyramid - ListA: " + pyramid.EvaluateStack(listA)); Console.WriteLine("Pyramid - ListB: " + pyramid.EvaluateStack(listB)); Console.WriteLine("Pyramid - ListC: " + pyramid.EvaluateStack(listC)); Console.WriteLine(); Console.WriteLine("Topple - ListA: " + topple.EvaluateStack(listA)); Console.WriteLine("Topple - ListB: " + topple.EvaluateStack(listB)); Console.WriteLine("Topple - ListC: " + topple.EvaluateStack(listC)); }
/* * Method: EvaluateStack() * Purpose: Evaluate a stack from [0] - [2] (3 elements) * Parameters: HeavyObjectList * Returns: double */ public double EvaluateStack(HeavyObjectList input) { //opposite of a pyramid, we need to look at mass and volume. //logically for a topple, the smallest shape should logically be on the bottom with the largest shape on top //looking at density. (least, middle, most) will topple but also (small,medium,large) shape //create a list to make the ideal senario List <float> topple = new List <float>(); for (IIterator i = input.CreateIterator(); !i.IsDone(); i.Next()) { topple.Add(i.CurrentItem().Density); } topple.Sort(); //this should give us a least,meduim,most denisty structure with least at [0]; //similar to the other structures, we can see if the list[0] is the same as topple[0] for the ideal toople structure if (input.At(0).Density == topple[0]) //if the bottom is the most dense { //we need to find the second most dense and see if it is in the middle if (input.At(1).Density == topple[1]) { //this gaurentees that we have a toople (because there us only 3 elements in every list, this would not work in a real world situation where there could be mutliple lists with different lengths). float total = 0.0f; foreach (float dens in topple) { total = total + dens; } float count = total / input.Length(); return((float)Math.Round(count)); } else //heavy,least,meduim { float total = 0.0f; foreach (float dens in topple) { total = total + dens; } float count = total / input.Length() + 15; return((float)Math.Round(count)); } } else if (input.At(0).Density == topple[1]) // we have a medium,heavy,least or meduim, least, heavy, more chance of topple than the previous else above { if (input.At(1).Density == topple[0]) { //medium,heavy,least float total = 0.0f; foreach (float dens in topple) { total = total + dens; } float count = total / input.Length() + 35; return((float)Math.Round(count)); } else //we have a medium,least,heavy { float total = 0.0f; foreach (float dens in topple) { total = total + dens; } float count = total / input.Length() + 25; //almost equal posiblity of it toppling wth senario (heavy,least,meduim) return((float)Math.Round(count)); } } else { //we have a least,meduim,heavy or least,heavy,medium if (input.At(1).Density == topple[1]) //meduim in the middle { //least,meduim,heavy, proabbly wont topple at all float total = 0.0f; foreach (float dens in topple) { total = total + dens; } float count = total / input.Length() + 55; return((float)Math.Round(count)); } else { //least,heavy,medium float total = 0.0f; foreach (float dens in topple) { total = total + dens; } float count = (float)Math.Round(total / input.Length() + 85); return(count); } } }
Image CreatePreviewImage(string s) { int height = 80; int width = 530; int lineLength = 18; int diameter = 30; int leftSpan = 3; int topSpan = 20; IIterator circleNodeIterator;//用于输出结点链表的指针 IIterator lineNodeIterator;//用于输出连接线链表的指针 LinkCircleNode headNode = null; LinkLineNode headLineNode = null; LinkCircleNode previousNode = null; LinkLineNode previousLineNode = null; LinkCircleNode currentNode = null; LinkLineNode currentLineNode = null; previousNode = headNode = new LinkCircleNode(leftSpan,topSpan,diameter,Color.Red,"H"); previousLineNode = headLineNode = new LinkLineNode(leftSpan + diameter,topSpan + diameter/2,leftSpan + diameter + lineLength,topSpan + diameter/2,lineWidth,Color.Red); for(int i = 0;i < s.Length;i++) { currentNode = new LinkCircleNode(leftSpan + (i + 1) * (lineLength + diameter),topSpan,diameter,Color.DarkTurquoise,s[i].ToString()); currentLineNode = new LinkLineNode(leftSpan + diameter + (i + 1) * (lineLength + diameter),topSpan + diameter/2,leftSpan + diameter + (i + 1) * (lineLength + diameter) + lineLength,topSpan + diameter/2,lineWidth,Color.Red); previousNode.Next = currentNode; previousLineNode.Next = currentLineNode; previousNode = currentNode; previousLineNode = currentLineNode; } if(currentNode != null) { currentNode.Next = null; currentLineNode.Next = null; } circleNodeIterator = headNode.CreateIterator(); lineNodeIterator = headLineNode.CreateIterator(); Bitmap bmp = new Bitmap(width,height); Graphics g = Graphics.FromImage(bmp); if(circleNodeIterator != null) { for(IIterator iterator = circleNodeIterator.First();!circleNodeIterator.IsDone();iterator = circleNodeIterator.Next()) { iterator.CurrentItem.Draw(g); } } if(lineNodeIterator != null) { for(IIterator iterator = lineNodeIterator.First();!lineNodeIterator.IsDone();iterator = lineNodeIterator.Next()) { iterator.CurrentItem.Draw(g); } } return bmp; }