stack

Debug Assertion Failed, vector subscript out of range

老子叫甜甜 提交于 2019-12-13 10:47:06
问题 my program should implement a threadsafe stack in c++ I get an error when I want to start the programm: Debug assertion Failed! ...\vector Line 1201 Expression: vector subscript out of range I absolutely don't know what's wrong with the code #include <condition_variable> #include <iostream> #include <memory> #include <mutex> #include <thread> #include <vector> #define NUM_ELEMENTS 10 using namespace std; class Stack { protected: vector<int> stack; int topOfStack; int maxSize; mutable mutex

How to delete the book that have been input and how to make the title, language, and name doesn't error if we put space on it? [closed]

左心房为你撑大大i 提交于 2019-12-13 09:53:27
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . Can anyone help me to make a new menu to delete all the books that have been entered? And how to make the title, name, and language can be entered with space? I've searched other questions about it, many of them using getline. But i don't understand how to use it on class like this. (Sorry my grammar

C++ Dynamic vs Stack Objects and How to Use Them [closed]

对着背影说爱祢 提交于 2019-12-13 09:47:27
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Follow-Up: Please head over to this question where there are actually some useful answers. 回答1: Instead of objects, think of "simpler"

std stack performance issues [closed]

天涯浪子 提交于 2019-12-13 09:41:56
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Recently I was trying to do some performance benchmarks, comparing std::stack<int, std::vector<int>> and my own simple implementation

Deep copying linked list

断了今生、忘了曾经 提交于 2019-12-13 09:13:06
问题 I'm trying to implement a stack on the heap using a linked list. However, for using the 'list' function I need to create a deep copy of the linked list, which i'm not completely sure how it's done. Here's a part of my code: class Stack { private: struct Node { int data; Node *next; }; Node *stackTop; public: Stack() {stackTop = nullptr;} Stack(const Stack& original); ~Stack(); bool isEmpty() const; int top() const; int pop(); void push(int newItem); }; Stack::~Stack() { delete stackTop; }

C# error: InvalidOperationException: Stack empty

倖福魔咒の 提交于 2019-12-13 08:51:44
问题 I have been working with a web application. It was running fun until I changed tables which were behind the app. I checked my code, and it looked fine to me. But I am keep getting this error, and not sure why. Can someone help? [InvalidOperationException: Stack empty.] System.Collections.Generic.Stack`1.Pop() +8625191 System.Web.UI.RenderTraceListenerList.EndRendering(TextWriter writer, Object renderedObject) +90 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,

Pop function on Linked list stack

廉价感情. 提交于 2019-12-13 08:26:40
问题 Hello I have a problem to returned variable from my pop function. I will be happy if you could help me. The function receives a pointer to the top of the list and should return the answer but I have a problem with a pointer to the list and intger the answer. Function Code - int pop(Node* top) { Node* tmp = top; int ans = tmp->next; top = top->next; delete tmp; return ans; } Node - struct Node { int num; Node* next; } Node* top = new Node; 回答1: The line int ans = tmp->next; appears to be the

std::string::c_str() overwrittes the previous one returned by a function

不羁的心 提交于 2019-12-13 07:51:44
问题 I could not understand that how can be the pointers same when the text size is equal. It seems like firstStringObj::c_str() overwrittes the previous one's pointer. #include <iostream> #include <string> #include <string> #include <stdio.h> std::string getConstCharAndModifyItWithANewString( const char* constchar ) { std::string stringAtStack( constchar ); stringAtStack += "::isModified"; return stringAtStack; } int main() { const char* firstConstCharPointer =

why is the value of LD_PRELOAD on the stack

蹲街弑〆低调 提交于 2019-12-13 07:37:41
问题 I'm studying buffer overflow and solving some wargames. There was a problem that all of the stack memory above the buffer is set to 0 except return address of main, which will be: buffer [0000000...][RET][000000...] and I can overwrite that RET. So I found some hints for solving this problem. It was to use LD_PRELOAD. Some people said that LD_PRELOAD's value is in somewhere of stack not only in environment variable area of stack. So I set LD_PRELOAD and search it and found it using gdb. $

Why is this implementation of a queue with two stacks immutable and thread safe?

99封情书 提交于 2019-12-13 07:12:18
问题 I've seen this way of implementing a queue with two stacks: https://stackoverflow.com/a/2050402/494094 And I've read that this way the queue is immutable and thread-safe. What's the point that separates this from a normal queue and makes it immutable and thread-safe? I'd really appreciate it if someone could explain it in a simple, non-professional way. 回答1: How to implement a queue using two stacks? explains more and has some code. If you do this in a low-level way you will have two memory