倒排队列的渐近分析(Asymptotic Analysis of Reversing a Queue)
void reverseQueue(queue<int>& Queue) { stack<int> Stack; while (!Queue.empty()) { Stack.push(Queue.front()); Queue.pop(); } while (!Stack.empty()) { Queue.push(Stack.top()); Stack.pop(); } }
我想知道这个函数的Big-O或Big-Theta符号是什么,如果我们用n个元素的队列来调用它的话。 它会是沿着O(n ^ 2)行的东西,因为我们推动并弹出n个元素两次,以便将它从栈中移回到队列中,并且以相反的顺序排列? 感谢您的任何帮助。
void reverseQueue(queue<int>& Queue) { stack<int> Stack; while (!Queue.empty()) { Stack.push(Queue.front()); Queue.pop(); } while (!Stack.empty()) { Queue.push(Stack.top()); Stack.pop(); } }
I was wondering what the Big-O or Big-Theta notation of this function would be, if we called it with a Queue of n elements. Would it be something along the lines of O(n^2), since we're pushing and popping n elements twice in order to move it from the stack back to the queue in a reversed order? Thank you for any help.
原文:https://stackoverflow.com/questions/50283059
最满意答案
所以我实际上最终解决了这个问题,方法是在Google地图上获取我所有标记的引用,然后将评级添加到与marker.getTitle()相关的字符串集中,并在getInfoWindow中对结果进行平均。
So I actually ended up fixing this problem by getting a reference to all of my markers on the Google map and then adding the ratings to a string set which correlated with the marker.getTitle(), and I average the results in the getInfoWindow.
相关问答
更多-
你本可以发布更多的代码,但如果你想这样做,那么你必须为所有布局(三种不同的布局)制作ID,然后是的,基本上找到他们的孩子EditTexts等。 我更喜欢通过制作可能出现在xml文件中的所有视图来解决这些问题(再次,如果你做对了),然后让它们中的一些看不见。 您可以通过在xml文件中设置属性来实现。 android:visibility = "visible" // the view is shown android:visibility = "invisible" // the view is hidden ...
-
好。 得到它了。 该按钮是片段布局的一部分。 因此,您没有活动类中的按钮实例。 如果要处理活动类上的按钮单击行为,可以使活动实现OnClickListener。 然后从片段覆盖onAttach()方法,如下所示: @Override public void onAttach(Context activity) { super.onAttach(activity); if(activity instanceof OnClickListener) mListener = (OnC ...
-
ArrayAdapter无法从膨胀的布局访问Textviews(ArrayAdapter Unable to access Textviews from inflated Layout)[2023-12-30]
slotNum和status字段的类型是什么? 如果它们是int值,则不能像这样调用setText : TextView num = (TextView) view.findViewById(R.id.txtSlotSA); num.setText(slot.slotNum); TextView status = (TextView) view.findViewById(R.id.txtStatusSA); status.setText(slot.status); 问题是当您使用setText方法的in ... -
所以我实际上最终解决了这个问题,方法是在Google地图上获取我所有标记的引用,然后将评级添加到与marker.getTitle()相关的字符串集中,并在getInfoWindow中对结果进行平均。 So I actually ended up fixing this problem by getting a reference to all of my markers on the Google map and then adding the ratings to a string set which c ...
-
Android充气布局对齐(Android inflated layout alignment)[2023-06-06]
没有XML很难看到,但通常当你调用inflate你应该传递一个根视图,否则你在XML布局中指定的任何布局参数都将丢失。 试试吧,也许吧? inflater = LayoutInflater.from(MainActivity.this); RelativeLayout layout = (RelativeLayout)findViewById(R.id.layout); View inflated = inflater.inflate(R.layout.layout, layout, false); lay ... -
使用此从布局获取TextView。 TextView tvCsAddLink = (TextView)rowLink.findViewById(R.id.tvCsAddLink); Use this to get TextView from layout. TextView tvCsAddLink = (TextView)rowLink.findViewById(R.id.tvCsAddLink);
-
试试这样: imageView = (ImageView) intilt .findViewById(R.id.contimg); Try like this: imageView = (ImageView) intilt .findViewById(R.id.contimg);
-
我经历过一些属性可以覆盖layout_width-attribute。 尝试从RelativeLayout中删除layout_centerHorizontal,layout_centerVertical和scaleType。 据我所知,他们无论如何都没有任何目的。 I have experienced that some attributes can override the layout_width-attribute. Try to remove layout_centerHorizontal, lay ...
-
我只用一个更改复制了你的代码:我删除了 tools:context="${relativePackage}.${activityClass}" 来自activity_verbs,它对我来说就像一个魅力: 我将带有代码的测试项目上传到DropBox,随时可以下载: https ://www.dropbox.com/s/8fcdab3rmx8zb57/ElaPinkSO.zip?dl = 0 PS结构很好的问题,干得好! I copied your code with only one change: I ...
-
我会尝试这样做,替换 inflater.inflate(R.layout.internetnotconnected, LLPureCard); 同 final View addedView = inflater.inflate(R.layout.internetnotconnected, null); LLPureCard.addView(addedView); 然后在onClick方法中替换该行 LLPureCard.removeView(((Activity) context).findViewBy ...