stack

C++ - Stack Pop() Function with Singly Linked list

佐手、 提交于 2019-12-08 07:13:03
问题 For starters this is apart of my current homework assignment for my Data Structures class. I am not asking for answers, I am asking for help. I have a stack class that is implementing a Linked List instead of an array. I am currently trying to write my pop() function. I have a node for my theBack part of the stack. I am just confused as to getting to the predecesor of my theBack node. Any help with this would be awesome! Thanks! 回答1: A stack is actually reasonably simple to implement as a

How to evaluate arithmetic expression using stack c?

旧街凉风 提交于 2019-12-08 06:45:47
问题 by now I just finish the expression turning to postfix expression, and I try to evaluate but something goes wrong and confusing me long time, and I just know how to fix it. This is my code turn to postfix expression: #include <stdio.h> #include <ctype.h> #include <stdlib.h> #define STACK_INIT_SIZE 20 #define STACKINCREMENT 10 #define MAXBUFFER 10 #define OK 1 #define ERROR 0 typedef char ElemType; typedef int Status; typedef struct { ElemType *base; ElemType *top; int stackSize; }sqStack;

Segments duplicated during fork()?

Deadly 提交于 2019-12-08 06:44:56
问题 I have studied that during a fork, the data and code segment of the parent process gets duplicated into the child process. Kindly see the program below. int main() { int a = 5; pid_t pid; pid = fork(); if(pid == 0) { printf("In child a = %d",a); } else { printf("In parent a = %d",a); } return 0; } Here a is in the stack segment of parent process as it is declared inside the function, main() . The child process should only get copy of the code and data segment of the parent process and not the

Double free or corruption error with Stack and Binary Expression Tree

十年热恋 提交于 2019-12-08 06:26:32
问题 I am getting the following error when trying to build a binary expression tree from a Stack. I believe the issue is where I am popping in the recursive function, I think I am popping on an empty stack but I don't know the solution. * glibc detected ./interp: double free or corruption (fasttop): 0x0934d018 ** Here is my code: //This is the main int main(int argc, char *argv[]){ TreeNode *node; StackNode *stack = NULL; push(&stack, "a"); push(&stack, "b"); push(&stack, "+"); //while (emptyStack

How to see variables stored on the stack with GDB

自作多情 提交于 2019-12-08 06:09:39
问题 I'm trying to figure out what is stored at a certain place on the stack with GDB. I have a statement: cmpl $0x176,-0x10(%ebp) In this function I'm comparing 0x176 to the -0x10(%ebp) and I am wondering if there is a way to see what is stored at -0x10(%ebp). 回答1: I am wondering if there is a way to see what is stored at -0x10(%ebp). Assuming you have compiled with debug info, info locals will tell you about all the local variables in current frame. After that, print (char*)&a_local - (char*)

Stack abstract data type in C

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 05:18:48
问题 Can you please tell me what I did wrong? I'm getting SIGSEGV (Segmentation fault) error. Is single linked list the best way to implement a stack abstract data type? I'm trying not to use global variables so that's why I used double pointers. #include <stdio.h> #include <stdlib.h> typedef struct stack{ int data; struct stack *next; }STACK; void push(STACK **head,STACK **tail,int n) { STACK *x; if(*head==NULL) { (*head)=malloc(sizeof(STACK)); (*head)->data=n; (*head)->next=NULL; *tail=*head; }

Difference between stack memory and heap memory [duplicate]

雨燕双飞 提交于 2019-12-08 05:13:52
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What and where are the stack and heap Where is heap memory and stack memory stored?I mean where on the harddisk?what are the limits of their size? 回答1: You should consider memory and hard-disk as opposites. Memory is the more expensive stuff that comes in sticks and is 1000x faster than hard disk. I don't think you'll be able to "find" the heap and stack memory the way you want to. The OS sets this up by

Flutter: Stack with two images in GestureDetectors: Problem with reordering

佐手、 提交于 2019-12-08 05:06:32
问题 Flutter: I have two images within a stack, each capable of being scaled by dragging it. The two images are positioned one below the other, so they're both fully visible on screen at first. When I drag the top or bottom image, either should become bigger and overlap the other picture. Therefor, the order in my stack has to change depending on which image I panDowned. I made it almost work, but there is problem I just don't understand. Initially, my top image is the "master" image. So, I can

Pointers to objects in C++ - what's on the stack/heap?

坚强是说给别人听的谎言 提交于 2019-12-08 05:04:27
问题 I started out with Java, so I am a bit confused on what's going on with the stack/heap on the following line: string *x = new string("Hello"); where x is a local variable. In C++, does ANYTHING happen on the stack at all in regards to that statement? I know from reading it says that the object is on the heap, but what about x ? In Java, x would be on the stack just holding the memory address that points to the object, but I haven't found a clear source that says what's happening in C++. 回答1:

Call stack time machine in Visual Studio 2010

笑着哭i 提交于 2019-12-08 04:30:37
问题 I know the title is a bit ambitious, but I am wondering if there is a way, after displaying a previous state in the call stack window (Visual Studio 2010) when debugging a C# program, to restart (like when hitting "Continue"/F5) from there. This would be particularly useful to debug a lambda expression that generates an exception, as there is no way to move outside. For a real OO code time machine, the historical state of all objects would need to be stored in memory, so I doubt it is