stack

How does one implement a “stackless” interpreted language?

不想你离开。 提交于 2019-12-02 16:22:45
I am making my own Lisp-like interpreted language, and I want to do tail call optimization. I want to free my interpreter from the C stack so I can manage my own jumps from function to function and my own stack magic to achieve TCO. (I really don't mean stackless per se, just the fact that calls don't add frames to the C stack. I would like to use a stack of my own that does not grow with tail calls). Like Stackless Python, and unlike Ruby or... standard Python I guess. But, as my language is a Lisp derivative, all evaluation of s-expressions is currently done recursively (because it's the

Thread-safe C++ stack

喜你入骨 提交于 2019-12-02 15:59:41
I'm new to C++ and am writing a multi-threaded app whereby different writers will be pushing objects onto a stack and readers pulling them off the stack (or at least pushing the pointer to an object).. Are there any structures built-into C++ which can handle this without adding locking code etc.? If not, what about the Boost libraries? EDIT: Hi. Thanks for the initial great answers. I guess one reason I thought this could be built-in was that I was thinking purely in x86 space and thought that a PUSH/POP of pointers should be an atomic action at the instruction level. I'm not sure if my

Push and Pop behaviour is strange, why?

自作多情 提交于 2019-12-02 15:50:03
问题 I have two classes, the one is addAlarm and second is Name,,, for now I am in addAlarm (addAlarm is subclass of UITableViewController), as it selects the row, then it goes to Name class as below Name *ob = [[Name alloc] initWithStyle:UITableViewStyleGrouped]; [self.navigationController pushViewController:ob animated:YES]; [ob release]; ob = nil; then there is UINavigationBar with addAlarm as back button by default, while Name is also subclass of UITableViewController I observe that when I

returning wrong address from pop function

穿精又带淫゛_ 提交于 2019-12-02 14:41:10
问题 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

How to implement 3 stacks with one array?

纵然是瞬间 提交于 2019-12-02 13:53:52
Sometimes, I come across the following interview question: How to implement 3 stacks with one array ? Of course, any static allocation is not a solution. Space (not time) efficient. You could: 1) Define two stacks beginning at the array endpoints and growing in opposite directions. 2) Define the third stack as starting in the middle and growing in any direction you want. 3) Redefine the Push op, so that when the operation is going to overwrite other stack, you shift the whole middle stack in the opposite direction before Pushing. You need to store the stack top for the first two stacks, and

c2955 Error - Use of Class template reuires argument list

。_饼干妹妹 提交于 2019-12-02 13:07:29
问题 So, I've tested vector and it seems to be running fine. However, I'm trying to implement a basic Stack class built off of my Vector class. I keep running into these errors when I go to build: stack.h(4): error C2955: 'Vector' : use of class template requires template argument list followed by: vector.h(11) : see declaration of 'Vector' stack.h(13) : see reference to class template instantiation 'Stack<T>' being compiled Here is the Vector.h file: #include<iostream> using namespace std; const

Java - Printing a message when data exceeds limit?

☆樱花仙子☆ 提交于 2019-12-02 12:37:47
I've got my code working, it's not pretty but it doe's the job :) Now I want to write a piece of code that stops the data from being loaded if there is 19 or more pieces of data in the text file and then display a message saying Invalid input for example. I'm not sure how to do this so any help would be appreciated. package stackandqueue; import java.util.*; import java.util.Stack; import java.util.Queue; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.LinkedList; import java.util.StringTokenizer;

C# Expand Dictionary or Hashtable to include Pop and Push (LIFO)

南楼画角 提交于 2019-12-02 11:04:41
问题 Looking for structure that contains the benefits of a stack but the ability to only contain one item that matches a key. For example Data comes in from various clients, I am only interested in the last piece of data from a particular client. So a dictionary would work very well. However I want to process the data from all the clients in a LIFO scenario, so a stack would be best. Any ideas on combining the two? 回答1: There are several ways to interpret what you want. For instance when you Push

stack overflow c++

。_饼干妹妹 提交于 2019-12-02 10:45:28
So i', trying to solve a task. a already have code, but system outs, "stack overflow" i'm new in c++ and my english isn't good so i'm sorry for misunderstanding =) #include <iostream> using namespace std; int main (){ int n; int x; int k = 0; // счетчик для рабочего массива int a [200000]; scanf("%d\n",&n); for (int i = 0; i< n; ++i){ std::cin >> x; if (x > 0){ k++; a[k] = x; }else if(x == 0){ for (int q = 1; q <= k; ++q){ // копирование a[k+q] = a[q]; } k *= 2; }else{ printf("%d %d\n",a[k],k); k--; } } system("pause"); } looks like algorithm works correctly, but only problem is stack. thanks