public void TestToArrayBasic() { Stack stk1; Object[] oArr; Int32 iNumberOfElements; String strValue; //[] Vanila test case - this gives an object array of the values in the stack stk1 = new Stack(); oArr = stk1.ToArray(); Assert.Equal(0, oArr.Length); iNumberOfElements = 10; for (int i = 0; i < iNumberOfElements; i++) stk1.Push(i); oArr = stk1.ToArray(); Array.Sort(oArr); for (int i = 0; i < oArr.Length; i++) { strValue = "Value_" + i; Assert.Equal((Int32)oArr[i], i); } }
public void PushingAndPopping() { var array = new[] { 1, 2 }; Stack stack = new Stack(array); stack.Push("last"); Assert.Equal(FILL_ME_IN, stack.ToArray()); var poppedValue = stack.Pop(); Assert.Equal(FILL_ME_IN, poppedValue); Assert.Equal(FILL_ME_IN, stack.ToArray()); }
public void PushingAndPopping() { var array = new[] { 1, 2 }; Stack stack = new Stack(array); stack.Push("last"); Assert.Equal(new object[] { "last", 2, 1 }, stack.ToArray()); var poppedValue = stack.Pop(); Assert.Equal("last", poppedValue); Assert.Equal(new object[] { 2, 1 }, stack.ToArray()); }
static void Main(string[] args) { var stackOfValues = new Stack<string>(); GetInitialValuesFromArgs(args, ref stackOfValues); var demoSet1 = new Set<string>(stackOfValues.ToArray()); Console.WriteLine(demoSet1.ToString()); var demoSet3 = new SortedSet(stackOfValues.ToArray()); Console.WriteLine(demoSet3.ToString()); Console.ReadKey(); }
public void PushingAndPopping() { var array = new[] { 1, 2 }; Stack stack = new Stack(array); stack.Push("last"); // Stack converts array into an array of objects. Assert.Equal(new object[] { (string)"last", (int)2, (int)1 }, stack.ToArray()); //Pay attention to this format of declaring things! ^^^ 'object' is the type of thing that's going in each position, // and in each position the type is specified. var poppedValue = stack.Pop(); Assert.Equal("last", poppedValue); Assert.Equal(new object[] { (int)2, (int)1}, stack.ToArray()); }
public void PushingAndPopping() { var array = new[] { 1, 2 }; Stack stack = new Stack(array); stack.Push("last"); // #ah ok. Stack starts off empty, then array elements are added to it one by one. The top of the stack, when displayed/converted to an array, // #is the front of the array. Hence 1 gets added in first, and then becomes the back element when 2 is added (first in, first out). // #When we push "last", it goes to the front of the stack. It will be the first thing popped out. Assert.Equal(new object[] { "last", 2, 1 }, stack.ToArray()); var poppedValue = stack.Pop(); Assert.Equal("last", poppedValue); Assert.Equal(new object[] { 2, 1 }, stack.ToArray()); }
public Action FindAction(Type typeOfAction) { // der Stack in ein Array liefert top of stack als erstes Element object[] allAction = Actions.ToArray(); for (int i = 0; i < allAction.Length; ++i) { if (allAction[i].GetType() == typeOfAction) { return(allAction[i] as Action); } } return(null); }
public static string ReadPassword() { Stack<string> passbits = new Stack<string>(); for (ConsoleKeyInfo cki = Console.ReadKey(true); cki.Key != ConsoleKey.Enter; cki = Console.ReadKey(true)) { if (cki.Key == ConsoleKey.Backspace) { if (passbits.Count == 0) continue; Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); Console.Write(" "); Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); passbits.Pop(); } else { Console.Write("*"); passbits.Push(cki.KeyChar.ToString()); } } string[] pass = passbits.ToArray(); Array.Reverse(pass); Console.Write(Environment.NewLine); return string.Join(string.Empty, pass); }
/// <summary> /// Converts an XMLstring to an array of GBaseElement (Name and Type) structures /// </summary> /// <param name="XMLString">An XML string of the form: field..type..field..type...</param> /// <returns>An array of GBaseElement that is the parsed, passed XMLstring</returns> public GBaseElement[] FieldsToGBaseElementArray(String XMLString) { Stack<GBaseElement> _elements = new Stack<GBaseElement>(); // Initially use a stack to hold the elements XMLString = XMLString.Replace("\t", "").Replace("\r", "").Replace("\n", ""); // Replace the tabs, newllines, and returns in the string // Loop until break is hit while (true) { _GBaseElement.Name = XMLString.Substring(XMLString.IndexOf("Name=\"") + 6, // Set the name to be the string between "Name=\"" and the next " XMLString.IndexOf("\"", XMLString.IndexOf("Name=\"") + 6) - (XMLString.IndexOf("Name=\"") + 6)).ToLower(); // Set the Type to be the string between <Type> and </Type> _GBaseElement.Type = GetXMLBetweenTags("Type", XMLString).ToLower(); _elements.Push(_GBaseElement); // Push the newly generated object into _elements XMLString = XMLString.Substring(XMLString.IndexOf("</Field>") + 8, // Get rid of the portion of the string that has been evaluated XMLString.Length - (XMLString.IndexOf("</Field>") + 8)); if (XMLString.Replace(" ", "").Length == 0) // Get rid of any left over spaces (sometimes they presist) and see if there is no more to look over break; } return _elements.ToArray(); // Return the stack as an array }
public void TestStackParamContrWrongParam() { Stack<int> stack = new Stack<int>(-2); Assert.AreEqual(stack.Count, 0); Assert.IsTrue(stack.IsEmpty); CollectionAssert.AreEqual(stack.ToArray(), new int[0]); }
static void Main(string[] args) { string message = Console.ReadLine(); Stack stack = new Stack(); foreach (var item in message) { if (!IsCiphered(stack, item.ToString())) { stack.Push(item.ToString()); } else { stack.Pop(); } } var result = stack.ToArray(); for (int i = result.Length - 1; i >= 0; i--) { Console.Write(result[i]); } }
public static string ReadPassword() { var passbits = new Stack<string>(); //keep reading for (ConsoleKeyInfo cki = Console.ReadKey(true); cki.Key != ConsoleKey.Enter; cki = Console.ReadKey(true)) { if (cki.Key == ConsoleKey.Backspace) { //rollback the cursor and write a space so it looks backspaced to the user Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); Console.Write(" "); Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); passbits.Pop(); } else { Console.Write("*"); passbits.Push(cki.KeyChar.ToString()); } } string[] pass = passbits.ToArray(); Array.Reverse(pass); Console.Write(Environment.NewLine); return string.Join(string.Empty, pass); }
private ViewResult InvokeViewShared(string viewType, object model = null, string viewName = null) { Stack parameters = new Stack(); if (model == null) { if (viewName == null) { } else { parameters.Push(viewName); } } else { if (viewName == null) { parameters.Push(model); } else { parameters.Push(viewName); parameters.Push(model); } } return (ViewResult)_controller.GetType().GetMethod(viewType, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, parameters.Cast<Object>().Select(p => p.GetType()).ToArray(), null).Invoke(_controller, parameters.ToArray()); }
private void btCherche_Click(object sender, EventArgs e) { if (ComboPok閙on.Text != "") { try { //TODO modifier l'acc鑣 au pok閙on par l'index du combo Pokemon p = X.PKlist[ComboPok閙on.SelectedIndex]; if (p.dependevo) { Pokemon evo = X.GetPok閙on(p.evolution.ToArray()[0].nom); Pokemon p2 = new Pokemon(); X.CopyPokemon(p, p2); p2.Oeuf1 = evo.Oeuf1; p2.Oeuf2 = evo.Oeuf2; X.argPokemon = p2; } else X.argPokemon = p; Stack<Capacite> cap = new Stack<Capacite>(); if (txtCapacit�Text == "" && txtCapacit�Text == "" && txtCapacit�Text == "" && txtCapacit�Text == "") { MessageBox.Show("Capacit� mal s閘ectionn�, click eul' nom dans la bo顃e!"); return; } if (txtCapacit�Text != "") cap.Push(Xblood.GetCapacite(txtCapacit�Text)); if (txtCapacit�Text != "") cap.Push(Xblood.GetCapacite(txtCapacit�Text)); if (txtCapacit�Text != "") cap.Push(Xblood.GetCapacite(txtCapacit�Text)); if (txtCapacit�Text != "") cap.Push(Xblood.GetCapacite(txtCapacit�Text)); X.argCapacite = cap.ToArray(); X.deepness = (int)NumUDDepth.Value; lblBranches.Text = ""; lblLeaf.Text = ""; lblResult.Text = "Recherche..."; btChercher.Enabled = false; btStop.Enabled = true; t = new Thread(new ThreadStart(X.StartThread)); //t.Priority = ThreadPriority.AboveNormal; t.Start(); timer1.Start(); } catch { MessageBox.Show("Pok閙on mal s閘ectionn�, click eul' nom dans la bo顃e!"); } } else TVr閟ultat.Nodes.Clear(); }
public void PushingAndPopping() { var array = new[] { 1, 2 }; /* Can an array have multiple types? Only an object array can? */ Stack stack = new Stack(array); Console.WriteLine(stack); stack.Push("last"); Assert.Equal(new object[] { (string)"last", (int)2, (int)1 }, stack.ToArray()); var poppedValue = stack.Pop(); Assert.Equal((string)"last", poppedValue); Assert.Equal(new object[] { (int)2, (int)1 }, stack.ToArray()); /* What is the difference between an array and a stack? The method of storing and retrieving the data. FIFO v. LIFO(FILO) */ }
public TreePath GetPath(Node node) { if (node == root) return TreePath.Empty; else { Stack<object> stack = new Stack<object>(); while (node != root) { stack.Push(node); node = node.Parent; } return new TreePath(stack.ToArray()); } }
static public int ToArray(IntPtr l) { try { System.Collections.Stack self = (System.Collections.Stack)checkSelf(l); var ret = self.ToArray(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
/// <summary> /// Convert a number to another base system based on the system's table /// </summary> public static string Convert(UInt64 number, string charactersTable) { var result = new Stack(); var radix = (UInt64)charactersTable.Length; do { var m = number % radix; result.Push(charactersTable[(int)m]); number /= radix; } while (number > 0); return string.Join(string.Empty, result.ToArray()); }
//Code borrowed from https://github.com/mstum/mstum.utils public static String Encode(ulong numberToEncode) { if (numberToEncode < 0) return null; Char[] cArray = Base36Chart_.ToArray(); var result = new Stack<char>(); while (numberToEncode != 0) { result.Push(cArray[numberToEncode % 36]); numberToEncode /= 36; } return new string(result.ToArray()); }
public string Find(Expression expression) { if (expression.NodeType == ExpressionType.Parameter) return null; _fieldParts = new Stack<string>(); _isBlocked = false; Visit(expression); var fieldName = string.Join(".", _fieldParts.ToArray()); if (_isBlocked) fieldName = null; return fieldName; }
static int ToArray(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); System.Collections.Stack obj = (System.Collections.Stack)ToLua.CheckObject(L, 1, typeof(System.Collections.Stack)); object[] o = obj.ToArray(); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// Enqueue SCC /// </summary> /// <param name="newSCC"></param> /// <param name="outgoingTransitionTable"></param> /// <param name="postTrace"></param> /// <param name="localCallStack"></param> /// <param name="isDeadLock"></param> public void enqueueSCC(int order, Dictionary<string, LocalPair> component, Dictionary<string, List<string>> outgoingTransitionTable, List<ConfigurationBase> postTrace, Stack<LocalPair> localCallStack, bool isDeadLock) { List<ConfigurationBase> preTrace = new List<ConfigurationBase>(localCallStack.Count); LocalPair[] localCallArray = localCallStack.ToArray(); for (int i = 1; i <localCallArray.Length; i++) { preTrace.Insert(0, localCallArray[i].configuration); if (localCallArray[i].configuration.Event == Constants.INITIAL_EVENT) { break; } } int loopIndex = isDeadLock ? -1 : preTrace.Count; preTrace.AddRange(postTrace); SCC newSCC = new SCC(component, outgoingTransitionTable, preTrace, loopIndex); queueSCCArray[order].Enqueue(newSCC); }
public void MethodStack() { s = new Stack(20); s.Push("Element"); if (!(s.Peek().Equals("Element"))) { Environment.Exit(-1); } Object[] objs = s.ToArray(); if (!(objs[0].Equals("Element"))) { Environment.Exit(-1); } }
public void generate() { string line = ""; string filename = ""; System.IO.StreamReader file = null; Stack<string> familynames = new Stack<string>(); Stack<string> firstnames = new Stack<string>(); Random random = new Random(); this.gender = random.Next(0,1).ToString(); file = new System.IO.StreamReader("names\\family-names"); while ((line = file.ReadLine()) != null) { familynames.Push(line); } file.Close(); if (this.gender == "0") { filename = "names\\male-names"; } else { filename = "names\\female-names"; } file = new System.IO.StreamReader(filename); while ((line = file.ReadLine()) != null) { firstnames.Push(line); } file.Close(); // there's got to be a better way to do this.. string []fnames = firstnames.ToArray(); this.firstname = fnames[random.Next(0, firstnames.Count)]; string[] lnames = familynames.ToArray(); this.lastname = lnames[random.Next(0, familynames.Count)]; }
public override void execute3(RunTimeValueBase thisObj,FunctionDefine functionDefine,SLOT returnSlot,SourceToken token,StackFrame stackframe,out bool success) { System.Collections.Stack stack = (System.Collections.Stack)((LinkObj <object>)((ASBinCode.rtData.rtObjectBase)thisObj).value).value; try { object obj = stack.ToArray(); stackframe.player.linktypemapper.storeLinkObject_ToSlot(obj,functionDefine.signature.returnType,returnSlot,bin,stackframe.player); //returnSlot.setValue((int)array.GetValue(index)); success = true; } catch (RuntimeLinkTypeMapper.TypeLinkClassException tlc) { success = false; stackframe.throwAneException(token,tlc.Message); } catch (KeyNotFoundException) { success = false; stackframe.throwAneException(token,(stack.Peek() != null ? stack.Peek().ToString() : (stack.ToString() + ".peek()的值")) + "没有链接到脚本"); } catch (ArgumentException a) { success = false; stackframe.throwAneException(token,a.Message); } catch (IndexOutOfRangeException i) { success = false; stackframe.throwAneException(token,i.Message); } catch (InvalidOperationException io) { success = false; stackframe.throwAneException(token,io.Message); } }
public void PushingAndPopping() { //this declares the new array var array = new[] { 1, 2 }; //I have no idea what Stack means yet. I think. But were putting the array in the "Stack" Stack stack = new Stack(array); //now we're pushing "last" into stack stack.Push("last"); //And checking if stack.ToArray() === the array we just pushed into, including the value ("last") we just pushed. Assert.Equal(new object[] { (string)"last", (int)2, (int)1 }, stack.ToArray()); //this assigns a new variable 'poppedValue' var poppedValue = stack.Pop(); //checking if (string)"last" and poppedValue are the same thing. .Pop() returns the value of the popped thing! Assert.Equal((string)"last", poppedValue); //checking if the array is now back to it's original state since we've popped out of it. Assert.Equal(new object[] { (int)2, (int)1 }, stack.ToArray()); }
public void PushingAndPopping() { var array = new[] { 1, 2 }; // Notice how an array is put onto the stack. It may not be what you expect. var stack = new Stack (array); stack.Push ("last"); CollectionAssert.AreEqual ((ICollection)stack, stack.ToArray (), "Converting this stack back into an Array may surprise you."); var poppedValue = stack.Pop (); Assert.AreEqual ("last", poppedValue, "Popped values come from the top. I suppose if they came from the bottom it would be called... Plop?"); CollectionAssert.AreEqual ((ICollection)stack, stack.ToArray (), "I'm not sure why this one is here.. I guess there wasn't enough material to create an AboutStacks..."); }
public static Symbol Execute(FunctionSymbol symbol, Stack<Symbol> arguments) { if(cached_functions == null) { LoadFunctionCache(); } if(!cached_functions.ContainsKey(symbol.Name)) { throw new InvalidFunctionException(symbol.Name); } FunctionCache function = cached_functions[symbol.Name]; if(arguments.Count != function.ArgumentCount && function.ArgumentCount >= 0) { throw new ArgumentException(symbol.Name); } if(function.RawSymbols) { if(function.ArgumentCount == -1) { return (Symbol)function.Method.Invoke(null, new object [] { arguments.ToArray() }); } else { return (Symbol)function.Method.Invoke(null, arguments.ToArray()); } } ArrayList resolved_arguments = new ArrayList(); while(arguments.Count > 0) { Symbol argument = arguments.Pop(); if(!(argument is ValueSymbol)) { throw new ArgumentException("argument must be ValueSymbol"); } resolved_arguments.Add((argument as ValueSymbol).Value); } double retval; if(function.ArgumentCount == -1) { retval = (double)function.Method.Invoke(null, new object [] { resolved_arguments.ToArray(typeof(double)) }); } else { retval = (double)function.Method.Invoke(null, resolved_arguments.ToArray()); } return new NumberSymbol(retval); }
private string doTransform(string number) { char c100 = '0', c010 = '0', c001 = '0'; string sCents = ""; char[] c = number.ToCharArray(); int i = number.LastIndexOf("."); if (i != -1) // deal with cents { if (c.Length == i + 1) // dot at last case 100. { throw new FormatException("Missing decimal digit"); } if (c.Length > i + 2) // two or more decimals { c010 = c[i + 1]; c001 = c[i + 2]; for (int j = i + 3; j < c.Length; j++) // validate all digits, even they are useless { validate(c[j]); } } else // only one decimal { c010 = c[i + 1]; } sCents = convert3Digits(c100, c010, c001); if (sCents != "") { sCents = sCents == "One" ? "One Cent" : (sCents + " Cents"); } i--; if (i == -1) // no integer case .01 { return sCents == "" ? "Zero Dollar" : sCents; } } if (i == -1) // no decimal point case { i = c.Length - 1; } int idxScale = 0; Stack s = new Stack(); do { c001 = c[i--]; c010 = i >= 0 ? c[i--] : '0'; c100 = i >= 0 ? c[i--] : '0'; string txt = convert3Digits(c100, c010, c001); if (txt != "") { if (s.Count > 0) { s.Push(" "); } s.Push(txt + scale[idxScale]); } if (i >= 0 && c[i] == ',') { i--; } idxScale++; } while (i >= 0 && idxScale < scale.Length); if (i >= 0 && idxScale >= scale.Length) // overflow if chars remain but scale run out { throw new FormatException("Number too large"); } if (s.Count > 0) { string dollar = String.Concat(s.ToArray()); return (dollar == "One" ? "One Dollar" : (dollar + " Dollars")) + (sCents == "" ? "" : (" and " + sCents)); } else // zero integer case 0.01 { return sCents == "" ? "Zero Dollar" : sCents; } }
public TreePath GetPath(TreeNodeAdv node) { if (node == _root) return TreePath.Empty; else { Stack<object> stack = new Stack<object>(); while (node != _root && node != null) { stack.Push(node.Tag); node = node.Parent; } return new TreePath(stack.ToArray()); } }
public void StackOrder() { var stack = new Stack<int>(); stack.Push(1); stack.Push(2); stack.Push(3); Assert.Equal(new[] {3, 2, 1 }, stack.ToArray()); }
public override object[] ToArray() { lock (stack) { return(stack.ToArray()); } }
public void StackOrder() { var stack = new Stack<int>(); stack.Push(1); stack.Push(2); stack.Push(3); Assert.Equal(FILL_ME_IN, stack.ToArray()); }
public void OldStack() { // Stack is another container type that can contain elements of different types var array = new[] { 1, 2 }; Stack stack = new Stack(array); stack.Push("last"); Assert.Equal(FILL_ME_IN, stack.ToArray()); }
/// <summary> /// 导出数据。 /// </summary> /// <param name="outputFilePath"></param> /// <param name="handler"></param> public void Export(string outputFilePath, RaiseChangedHandler handler) { lock (this) { if (nodes != null && nodes.Count > 0 && !string.IsNullOrEmpty(outputFilePath)) { this.RaiseChanged(handler, "开始检索数据..."); Stack<NodeValue> stack = null; Dictionary<String, List<String>> dict = new Dictionary<string, List<string>>(); foreach (TreeNode n in nodes) { stack = new Stack<NodeValue>(); this.GetAllNodeValue(n, stack); if (stack.Count > 0) { this.SetOutputData(stack.ToArray(), ref dict); } } ExportImportManifest mainfset = new ExportImportManifest("2.0"); mainfset.TeacherID = this.teacherID; List<String> list_ClassID_CatalogID = new List<string>(); List<LocalStudentWorkStore> listStore = new List<LocalStudentWorkStore>(); if (dict != null && dict.Count > 0) { #region 检索存储文件。 this.RaiseChanged(handler, "开始加载检索文件..."); foreach (string key in dict.Keys) { string[] arr = key.Split('_'); if (arr != null && arr.Length > 1) { LocalStudentWorkStore store = LocalStudentWorkStore.DeSerializer(this.teacherID, arr[1], arr[0]); if (store != null && store.Students != null) { list_ClassID_CatalogID.Add(key); List<String> list = dict[key]; if (list != null && list.Count > 0 && (list.Count != store.Students.Count)) { List<LocalStudent> removeStudents = new List<LocalStudent>(); foreach (LocalStudent ls in store.Students) { if (!list.Contains(ls.StudentID)) { removeStudents.Add(ls); } } if (removeStudents.Count > 0) { store.Students.Remove(removeStudents.ToArray()); } } listStore.Add(store); } } } #endregion } if (listStore.Count > 0) { mainfset.ClassID_CatalogID = list_ClassID_CatalogID.ToArray(); this.RaiseChanged(handler, "创建导出清单文件..."); outputFilePath = outputFilePath.Replace(Path.GetExtension(outputFilePath), ".zip"); using (FileStream outputStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write)) { this.RaiseChanged(handler, "创建压缩文件..."); Crc32 crc = new Crc32(); using (ZipOutputStream zipStream = new ZipOutputStream(outputStream)) { zipStream.SetLevel(9); byte[] data = UtilTools.Serializer<ExportImportManifest>(mainfset); if (data != null) { this.RaiseChanged(handler, "压缩导出清单文件..."); ZipEntry entry = new ZipEntry("ExportImportManifest.xml"); entry.DateTime = DateTime.Now; entry.Size = data.Length; crc.Reset(); crc.Update(data); entry.Crc = crc.Value; zipStream.PutNextEntry(entry); zipStream.Write(data, 0, data.Length); zipStream.CloseEntry(); } this.RaiseChanged(handler, "开始抽取压缩作品数据..."); this.BuildZipFile(zipStream,crc, listStore, handler); this.RaiseChanged(handler, "压缩作品数据完成"); } } this.RaiseChanged(handler, "作品数据导出完成"); } } } }
public FindResult Find(Expression expression) { if (expression.NodeType == ExpressionType.Parameter) return null; _fieldParts = new Stack<string>(); _isBlocked = false; _bsonMemberMap = null; Visit(expression); var fieldName = string.Join(".", _fieldParts.ToArray()); if (_isBlocked) return null; return new FindResult { FieldName = fieldName, MemberMap = _bsonMemberMap }; }
public override Object[] ToArray() { lock (_root) { return(_s.ToArray()); } }