stack

Does the iOS SDK provide queues and stacks?

大兔子大兔子 提交于 2019-12-02 20:10:10
I'm writing an iPhone app, and I'm surprised that there seem to be no NSQueue or NSStack classes in Apple's Foundation Framework . I see that it would be quite easy to roll my own, starting with an NSMutableArray , so I'll do that unless I've missed something. Have I missed something? as far as I know there is no generic class avaialbe. Try using the NSMutableArray, add via addObject and get first/last via objectAtIndex and removeObjectAtIndex. Tommy Herbert Here's my Stack class, in case it's useful to those who come after me. As you can see, the pop method involves enough code that you'd

c# structs/classes stack/heap control?

别来无恙 提交于 2019-12-02 19:33:48
so in c++ it's very easy. you want whatever class/struct to be allocated on the heap, use new. if you want it on the stack, don't use new. in C# we always use the new keyword, and depending on whether it's a struct or a class it's allocated either on the stack or on the heap (structs go to the stack, classes to the heap) - and in some applications there can be a HUGE performance difference when changing the design such that only those objects go to the heap that really belong there. What I wonder is - is there a direct way to control where an object is allocated independant of whether it's

How come Go doesn't have stackoverflows

不羁的心 提交于 2019-12-02 19:06:43
I read in this presentation http://golang.org/doc/ExpressivenessOfGo.pdf page 42: Safe - no stack overflows How is this possible? and/or how does Go works to avoid this? It's a feature called "segmented stacks": every goroutine has its own stack, allocated on the heap . In the simplest case, programming language implementations use a single stack per process/address space, commonly managed with special processor instructions called push and pop (or something like that) and implemented as a dynamic array of stack frames starting at a fixed address (commonly, the top of virtual memory). That is

Why do Queue(T) and Stack(T) not implement ICollection(T)?

有些话、适合烂在心里 提交于 2019-12-02 18:22:20
Before I even ask, let me get the obvious answer out of the way: The ICollection<T> interface includes a Remove method to remove an arbitrary element, which Queue<T> and Stack<T> can't really support (since they can only remove "end" elements). OK, I realize that. Actually, my question is not specifically about the Queue<T> or Stack<T> collection types; rather, it's about the design decision of not implementing ICollection<T> for any generic type that is essentially a collection of T values. Here's what I find odd. Say I have a method that accepts an arbitrary collection of T , and for the

How to fix a type error when working with stack.top() in the <stack> library in c++

老子叫甜甜 提交于 2019-12-02 17:45:50
问题 I'm trying to implement a function in my linked list that pushes the values of one list into a stack, and then pops off those values into another list. The problem is, when I try to std::cout << x , the first stack's topmost element, I get this error: c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ostream:682:5: error: no type named 'type' in 'struct std::enable_if<false, std::basic_ostream<char>&>' #include <iostream> #include <cstddef> #include <string> #include <stack> #include <vector> using

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause''

半腔热情 提交于 2019-12-02 17:45:45
问题 <?php require 'database.php'; $id = 0; if ( !empty($_GET['user_id'])) { $id = $_REQUEST['user_id']; } if ( !empty($_POST)) { // keep track post values $id = $_POST['user_id']; // delete data $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "DELETE FROM admin WHERE id = ?"; ===> Wrong on here.. //LINE18 $q = $pdo->prepare($sql); $q->execute(array($id)); Database::disconnect(); header("Location: index.php"); } ?> somebody can help me? why i got

Save and restore trap state? Easy way to manage multiple handlers for traps?

假如想象 提交于 2019-12-02 17:38:32
What is a good way to override bash trap handlers that don't permanently trample existing ones that may or may not already be set? What about dynamically managing arbitrary chains of trap routines? Is there a way to save the current state of the trap handlers so they can be restored later? Save and Restore Your Trap Handler State in Bash I would submit the following stack implementation to track and restore trap state. Using this method, I am able to push trap changes and then pop them away when I'm done with them. This could also be used to chain many trap routines together. See the following

What do Push and Pop mean for Stacks?

≯℡__Kan透↙ 提交于 2019-12-02 17:33:52
long story short my lecturer is crap, and was showing us infix to prefix stacks via an overhead projector and his bigass shadow was blocking everything so i missed the important stuff he was referring to push and pop, push = 0 pop = x he gave an example but i cant see how he gets his answer at all, 2*3/(2-1)+5*(4-1) step 1 Reverse : )1-4(*5+)1-2(/3*2 ok i can see that he then went on writing x's and o's operations and i got totally lost answer 14-5*12-32*/+ then reversed again to get +/*23-21*5-41 if some one could explain to me the push pop so i could understand i would be very greatful, i

What is the difference between kernel stack and user stack?

馋奶兔 提交于 2019-12-02 17:20:30
What is the need of using two different stacks in same program? How does trap change the current stack of program from user stack to kernel stack? How does it come back to user stack after completing system call? Does every process have a kernel and user stack? There is one "kernel stack" per CPU. There is one "user stack" for each process, though each thread has its own stack, including both user and kernel threads. How "trapping changes the stack" is actually fairly simple. The CPU changes processes or "modes", as a result of an interrupt. The interrupt can occur for many different reasons -

C# - Garbage Collection

余生颓废 提交于 2019-12-02 17:19:20
Ok so I understand about the stack and the heap (values live on the Stack, references on the Heap). When I declare a new instance of a Class, this lives on the heap, with a reference to this point in memory on the stack. I also know that C# does it's own Garbage Collection (ie. It determines when an instanciated class is no longer in use and reclaims the memory). I have 2 questions: Is my understanding of Garbage Collection correct? Can I do my own? If so is there any real benefit to doing this myself or should I just leave it. I ask because I have a method in a For loop. Every time I go