stack

Does PHP have a peek array operation?

泪湿孤枕 提交于 2019-12-12 12:16:55
问题 I would like to peek at the first element of an array. This operation would be equivalent to this code: function peek($list) { $item = array_shift($list); array_unshift($list, $item); return $item; } This code just seems really heavy to me and peek is often provided by queue and stack libraries. Does php have an already built function or some more efficient way to do this? I searched php.net but was unable to find anything. Additional note for clarity: The array is not necessarily numerically

C++ Stack around a variable is corrupted

旧城冷巷雨未停 提交于 2019-12-12 12:06:50
问题 I'm getting the following error from the code I've written - Run-Time Check Failure #2 - Stack around the variable 'pChar' was corrupted From research it is suggestive that the problem has to do with pHexValueBuffer = new char[256] and the memset and how I'm using the veritable - to store values to return a Hex number instead of Decimal. My research suggests that somehow I'm going out of bounds with the memory I've set, just not understanding the how. Any suggestions on how to fix the issue?

Using stack defined in C++ stl

帅比萌擦擦* 提交于 2019-12-12 11:01:40
问题 #include <stack> using namespace std; int main() { stack<int> s; int i; for (i = 0; i <= 10; i++) { s.push(i); } for (i = 0; i <= 10; i++) { printf("%d", s.pop()); } } Whats wrong with the code above? Error: In function int main() : aggregate value used where an integer was expected 回答1: stack::pop is a void function which just discards the top element on the stack, in order to get the value you want to use stack::top. The reason this is so is for exception safety reasons (what happens if the

GWT StackLayoutPanel: dynamic and automatic height

孤街醉人 提交于 2019-12-12 10:49:57
问题 I'm using a StackLayoutPanel to show stacked emails of a conversation a la gmail where the header is the sender and the child the email's body. For the dynamic nature of this, I can only estimate the height of my stack in code. To estimate the body's height I could get the client's window's width then roughly guess how many lines the body occupies. But this is laborious and likely to be wrong. My question is: is there a way for the StackLayoutPanel, as for GWT API 2.2, to know and so set

Segmentation fault with ulimit set correctly

ぃ、小莉子 提交于 2019-12-12 10:04:40
问题 I tried to help an OP on this question. I found out that a code like the one below causes segmentation fault randomly even if the stack is set to 2000 Kbytes. int main () { int a[510000]; a[509999] = 1; printf("%d", a[509999]); return 0; } As you can see the array is 510000 x 4 bytes = 2040000 bytes. The stack is set to 2000 Kbytes (2048000 bytes) using ulimit command: ulimit -s 2000 ulimit -Ss 2000 Based on those numbers the application has room to store the array, but randomly it return

How to call a function based on list entry?

[亡魂溺海] 提交于 2019-12-12 09:56:38
问题 I'm currently working on an experiment where I'm implementing an interpreter for an old in-game scripting language. It's a forth based language, so I figure it would be fairly easy to just have the instructions (once verified and santized) put into a big list. Once I've got the code in a list, I am trying to iterate through the entire program in a for loop that processes the instructions one at a time. Certain items, like strings, could be placed onto a variable that holds the current stack,

geom_text on only top part of stacked bar plot

▼魔方 西西 提交于 2019-12-12 08:57:04
问题 I would like to have labels on only the top part of my stacked bar plot. Here is my data frame: #create data frame building <- c("Burj \nKhalifa", "Zifeng \nTower", "Bank of \nAmerica Tower", "Burj Al Arab", "Emirates \nTower One", "New York \nTimes Tower", "Emirates \nTower Two", "Rose Rayhaan \nby Rotana", "The \nPinnacle", "Minsheng \nBank Building") occupiable<- c(585, 317, 235, 198, 241, 220, 213, 237, 265, 237) nonoccupiable <- c(244, 133, 131, 124, 113, 99, 97, 96, 95, 94) df.build <-

Does Stack<> constructor reverse the stack when being initialized from other one?

試著忘記壹切 提交于 2019-12-12 08:50:18
问题 Here is the code: var s = new Stack<int>(); s.Push(1); s.Push(2); s.Push(3); s.Push(4); var ns = new Stack<int>(s); var nss = new Stack<int>(new Stack<int>(s)); and then let's see the result tbLog.Text += "s stack:"; while(s.Count > 0) { tbLog.Text += s.Pop() + ","; } tbLog.Text += Environment.NewLine; tbLog.Text += "ns stack:"; while (ns.Count > 0) { tbLog.Text += ns.Pop() + ","; } tbLog.Text += Environment.NewLine; tbLog.Text += "nss stack:"; while (nss.Count > 0) { tbLog.Text += nss.Pop()

Unable to get thread dump? Any ideas why my app blocks?

眉间皱痕 提交于 2019-12-12 08:36:42
问题 I have a basic java server app that has 100 worker threads that do simple HEAD requests on urls. I'm using HttpClient 4.x for this. A few minutes into the run my program just freezes for a couple minutes and I cannot figure out why. Check out the screen shot of what visual vm monitor reports. You can see it flatline. During this time I'm unable to get a good thread dump and visual vm just freezes until it's unblocked. Does anyone have any ideas on what I can do to try and start debugging this

Exception Handling in C - What is the use of setjmp() returning 0?

感情迁移 提交于 2019-12-12 08:08:22
问题 I have a few questions relating to setjmp/longjmp usage - What is the use of setjmp(jmp___buf stackVariables) returning 0. It is a default, which we cannot influence. Is the only significance of setjmp(stackVariables) is to push the stack in stackVariables. And basically 0 tells us if the stack was pushed on stack_variables successfully. Their is one occasion when the value is non-zero (any non-zero) when you return from a longjmp. What is returning from a lomgjmp, when do you return from