stack

Is it possible to create an instance of a class on the stack?

时光毁灭记忆、已成空白 提交于 2019-12-02 10:29:52
I know that in C++ you can create an instance of a class on the stack like MyClass mc = MyClass(8.2); or on the heap like MyClass * mc = new MyClass(8.2); Can you do the same thing in C#? The only way I ever create a class in C# is by new ing it. No, it's not possible. All instances of all classes are always allocated on the heap. It is value types, including user defined struct types, that hold values, rather than references to values elsewhere, that can store a value in whatever location that variable happens to store its value in, which may not be the heap. 来源: https://stackoverflow.com

Refill Stack using Node Implementation

梦想与她 提交于 2019-12-02 10:21:11
I'm having a hard time refilling the stack after i take it all off in order to print it out. I am using node implementation so i think this fact is what is confusing me. Any suggestions would be appreciated, thank you. This is my original stack::print() // Function to print Gumball info field (color and counter) void Stack::print() { Node *p; Type x; while(top != NULL) { p = top; x = p -> getinfo(); cout << " " << x.color << " " << " " << x.counter << endl << endl; top = p -> getnext(); } return; } This is my stack with my attempt to loop and store in temp. It compiles but still is not working

how do I reverse a stack using another stack in java [closed]

▼魔方 西西 提交于 2019-12-02 09:52:45
Hi I am trying to reverse a stack(one I coded myself) using another empty stack. For some reason it is not working properly. Can anyone help me with this ? public static void main(String[] args) { Stack stack1 = new Stack(); //filling the stack with numbers from 0 to 4 for(int i = 0; i < Constants.MAX_ELMNTS; i++){ stack1.push(new Integer(i)); System.out.println(i); } Stack reverse = new Stack(); while(stack1.getNbElements() > 0){ reverse.push(stack1.pop()); } while(!stack1.isEmpty()){ Integer value = (Integer)stack1.pop(); System.out.println(value); reverse.push(value); } 来源: https:/

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

戏子无情 提交于 2019-12-02 09:15:32
<?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 Uncaught exception 'PDOException' with message 'SQLSTATE[42S22] sorry my english is bad, thanks The

Does pushing a register empty that register?

拈花ヽ惹草 提交于 2019-12-02 08:48:19
I have read many books and instructions on this, but one thing that is never specified is what happens to a register after you push it on the stack. For example if you write in assembly "push ECX", the contents of the ECX register will be pushed on the stack (obviously). What I don't know is, once you did this, does the ECX register keep the value it contained before the push, or did it empty itself after the push? CPUs almost always copy , not copy + zero-the-src . Despite instruction mnemonics like mov for "move", the actual operation is "copy" (between registers), or load or store from/to

C# checking if expression is brackets valid [closed]

假如想象 提交于 2019-12-02 08:44:37
The expression: "( a[i]+{-1}*(8-9) )" should return true since it is valid to write syntax like this. Every left bracket has a right closer in the correct place and all brackets are at legal positions. I tried to do this via one stack and I know where I'm wrong but I want to know a relevant way to solve this. thx! My poor poor wrong code: string expression = "( a[i]+{-1}*(8-9) ) "; Stack<char> expStack = new Stack<char>(); List<char> rightBracketsHolder = new List<char>(); for (int i = 0; i < expression.Length; i++) { if (expression[i] == '{') { expStack.Push('}'); Console.Write("}" + " "); }

returning wrong address from pop function

此生再无相见时 提交于 2019-12-02 07:54:05
After solving other issues with my struct, my push works as intended however my pop returns the wrong address and I'm not sure why - QNode* const Q_Pop(Q* const pointerQ){ ... // empty check QNode* tempNode = pointerQ->front.next; pointerQ->front.next = (tempNode->next); tempNode->next->prev = &(pointerQ->front); return tempNode; } I'm fairly certain my logic for the actual removal and relinking of the stack is correct but my use of pointers and returning them is messed up. struct - struct QueueNode { struct QueueNode *prev; /* Previous list element. */ struct QueueNode *next; /* Next list

Changing a struct on the stack inside function

邮差的信 提交于 2019-12-02 07:43:40
问题 I am working through the Learn C the Hard Way and I am currently stuck on the extra credit exercise number 16. I am currently trying to adapt their code and making the struct on the stack instead of the heap but my code is giving me segmentation fault and I am unsure why or how to proceed. Any advice is greatly appreciated. #include <stdio.h> #include <stdlib.h> #include <string.h> struct Person { char *name; int age; int height; int weight; }; void Person_create(struct Person p,char *name

std::cout statements evaluation order [duplicate]

谁说胖子不能爱 提交于 2019-12-02 07:35:57
This question already has an answer here: cout << order of call to functions it prints? 3 answers What is wrong with the pop() function why doesn't it work correctly? class stack{ int *p, *Cursor; int size ; public: stack(int sz) {Cursor = p = new int[size=sz+1];} //consider the stack empty when its size is 1 ~stack() {delete[] p;} //Cursor and P will be destroyed when the program finishes void push(int x) {Cursor+=1; *Cursor=x; size++;} int pop() {if(Cursor == p) return -1; int temp = *Cursor; Cursor--; size--; return (temp);} bool isEmpty(){return(Cursor == p);} bool isFull(){return(Cursor =

gcc, inline assembly - pushad/popad missing?

試著忘記壹切 提交于 2019-12-02 07:27:45
问题 Any way to avoid having to copy-paste the pushad / popad instruction body into my code? Because gcc (current flags: -Wall -m32 ) complains that __asm__("pushad;"); Error: no such instruction: `pushad' __asm__("popad;"); Error: no such instruction: `popad' 回答1: GCC use AT/T assembly syntax, while pushad/popad are Intel convention, try this: __asm__("pushal;"); __asm__("popal;"); 来源: https://stackoverflow.com/questions/37157552/gcc-inline-assembly-pushad-popad-missing