stack

Converting from Infix to Postfix using stacks (c++)

百般思念 提交于 2019-12-25 05:46:08
问题 I'm currently working on a project to convert from postfix to infix using a stack in the form of a singly linked list. I've managed to convert expressions such as ab+ to (a+b) however when the expression gets longer such as ab+cd*- . It doesn't work. I'm considering pushing the previously converted expression back onto the stack however the stack is of type char and the expression is a string and it complains when I try to push it back. Should I make it a template and if so how would I do it

Proc crashes even if it allocates less memory than limited by ulimit

谁说胖子不能爱 提交于 2019-12-25 04:39:21
问题 I have set stack size to 2000Kb by ulimit -s 2000 and ulimit -Ss 2000 for hard limit. And in the below program i have allocated appox 2040000(510000 x 4) bytes which is less than i limited i.e,. 2048000(2000*4)bytes but i see that my program crashes! Can anybody suggest why this happens. #include <stdio.h> #include <malloc.h> int main() { int a[510000] = {0}; a[510000] = 1; printf("%d", a[510000]); fflush(stdout); sleep(70); } EDIT 1: Crash is not because of the array index out of bound as i

Stacking rectangles to into the most square-like arrangement possible

时光毁灭记忆、已成空白 提交于 2019-12-25 04:33:22
问题 My Situation I have a N rectangles The rectangles all have the same shape (for example 2 inches wide x 1 inch tall) - Let's refer to this size as Sw and Sh for the width and height I want to position these rectangles in a grid such that the rects completely on top and next to each other - like what you would see in a spreadsheet What I need is this: Given N, Sw, and Sh what are the number of rows (R) and columns (C) that would stack these rects into the most square-like arrangement possible

stack of actions for one sparite in cocos2d

荒凉一梦 提交于 2019-12-25 04:05:32
问题 I've got a question: My games hero can jump ( CCJumpTo ) and move to forward and backward direction ( CCMoveTo ). I faced with problem: if game recived a command from user to move the hero, but in this time hero is jumping ( CCJumpTo ), how can I do this command after the end of jumping. (can I use some stack of actions for one sparite in cocos2d) I can't use immediately [self.sprite stopAllActions]; to begin CCMoveTo because the hero have to finish the jump action and if I use CCMoveTo the

Using Pointers in Objective-C?

。_饼干妹妹 提交于 2019-12-25 02:40:21
问题 Whenever Apple creates its own custom classes, it often creates a pointer to the object instead of the actual object itself. For example, instead of doing: Class object They often do: Class *object = [[Class alloc] init]; Why are pointers so commonly used instead of putting the object on the stack? Is there some technical reason for this, because I don't see any immediate benefit of doing so. EDIT: If Objective-C doesn't support objects on the stack how can they create any non-pointers? I

Linked List implementation for a stack

早过忘川 提交于 2019-12-25 02:07:15
问题 Here is my implemetation of stack with linkedlist STACK using linked list STACK-EMPTY: if L.head == NIL return True else return False PUSH(x): x.next = L.head if L.head != NIL L.head.prev = x L.head = x x.prev = NIL POP(): x = L.head L.head = x.next x.next.prev = L.head return x would you validate this? how to improve ? thanks 回答1: You can improvement the consistency of your data structure: The prev of the list head is always NIL An element which is not in the list has next and prev set to

Push Each Character of a String Into a Stack MIPS

拥有回忆 提交于 2019-12-25 01:56:04
问题 So I'm working on a project in MIPS to check if a string input by the user is a palindrome or not. The part I'm stuck on is reading the string and pushing each character of the string into the stack one by one (the PushLoop part of the code). When I debug it, the program seems to think I haven't entered anything at all. Here's what I have so far: .text main: li $v0, 4 # Prints str1 la $a0, str1 syscall jal Init # Sets $s0 equal to $sp to compare if the stack is empty later li $v0, 8 # Read

Evaluating an infix expression python

瘦欲@ 提交于 2019-12-25 01:53:26
问题 My task is to evaluate a fully parenthesized infix expression using a stack. A Stack class has been written for me and I must not change or modify the Stack class. Here are the step by step directions for how to evaluate the infix expression: Just scan the expression from left to right. If it is anything other than a ), push it onto the stack. When you encounter a ), pop from the stack 4 times, do the math and push the value onto the stack. At the end you will have just one value in the stack

I'm confused on how i'd go about overloading the + operator on a stack using a linked list

做~自己de王妃 提交于 2019-12-25 01:31:14
问题 First of all, i know how to do this using a linked list in general, which i will paste below: List operator+(const List& l) const { // copy the first list List t = *this; Node *n = l.head; // iterate through the second list and copy each element to the new list while (n != NULL && !t.IsFull()) { t.InsertAfter(n->data); n = n->link; } return t; } Now in my Stack i have something that looks like this: Stack operator+(const Stack& s) const { // copy the first list Stack t = *this; Node *n = s

How to sum elements of a stack

橙三吉。 提交于 2019-12-25 01:28:02
问题 import java.util.*; public class multiple { public static int userNumber; public static int userChoice; static Stack<Object> stack = new Stack<Object>(); static int[] list = new int[100]; public static void main(String[] args) { introduction(); multiple(); printStack(stack); } public static void introduction() { Scanner input = new Scanner(System.in); System.out.print("Welcome to the program, please enter the number less than 100 that you would like " + "to find whoes number \nbelow have