倒排队列的渐近分析(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
2023-01-30 08:01

满意答案

所以我实际上最终解决了这个问题,方法是在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.

相关问答

更多

如何从膨胀的布局中获取数据(how to get data from inflated layout)

你本可以发布更多的代码,但如果你想这样做,那么你必须为所有布局(三种不同的布局)制作ID,然后是的,基本上找到他们的孩子EditTexts等。 我更喜欢通过制作可能出现在xml文件中的所有视图来解决这些问题(再次,如果你做对了),然后让它们中的一些看不见。 您可以通过在xml文件中设置属性来实现。 android:visibility = "visible" // the view is shown android:visibility = "invisible" // the view is h...

为什么setOnClickListener不适用于膨胀按钮?(why setOnClickListener not working for inflated button?)

好。 得到它了。 该按钮是片段布局的一部分。 因此,您没有活动类中的按钮实例。 如果要处理活动类上的按钮单击行为,可以使活动实现OnClickListener。 然后从片段覆盖onAttach()方法,如下所示: @Override public void onAttach(Context activity) { super.onAttach(activity); if(activity instanceof OnClickListener) mListener =...

ArrayAdapter无法从膨胀的布局访问Textviews(ArrayAdapter Unable to access Textviews from inflated Layout)

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...

setRating不适用于膨胀的布局 - Android(setRating not working on an inflated layout-Android)

所以我实际上最终解决了这个问题,方法是在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 wh...

Android充气布局对齐(Android inflated layout alignment)

没有XML很难看到,但通常当你调用inflate你应该传递一个根视图,否则你在XML布局中指定的任何布局参数都将丢失。 试试吧,也许吧? inflater = LayoutInflater.from(MainActivity.this); RelativeLayout layout = (RelativeLayout)findViewById(R.id.layout); View inflated = inflater.inflate(R.layout.layout, layout, false)...

setText()不适用于虚拟布局(setText() not working on inflated layout)

使用此从布局获取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可绘制的膨胀布局(Change ImageView drawable of an inflated layout)

试试这样: imageView = (ImageView) intilt .findViewById(R.id.contimg); Try like this: imageView = (ImageView) intilt .findViewById(R.id.contimg);

为什么这种布局没有膨胀到全宽?(Why is this layout not inflated to full width?)

我经历过一些属性可以覆盖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...

行布局在Android中没有膨胀(Row layout not inflated in Android)

我只用一个更改复制了你的代码:我删除了 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 chan...

Android - 从线性布局中删除膨胀的布局xml(Android - Removing inflated layout xml from a Linear Layout)

我会尝试这样做,替换 inflater.inflate(R.layout.internetnotconnected, LLPureCard); 同 final View addedView = inflater.inflate(R.layout.internetnotconnected, null); LLPureCard.addView(addedView); 然后在onClick方法中替换该行 LLPureCard.removeView(((Activity) context).findV...

相关文章

更多

Hadoop mapred-queue-acls 配置

Hadoop作业提交时可以指定相应的队列,例如:-Dmapred.job.queue.name=que ...

zz Data Analysis Process

An interesting article....easy to understand. Summa ...

Solr参数(Analysis Collection Common CoreAdmin)

一.Analysis 1.analysis.query:Holds the query to be a ...

计算机病毒及其防治 Computer Virus Analysis and Antivirus

Episode I 计算机病毒的历史 FUDAN UNIVERSITY 3 ...

Solr官方文档系列——Text Analysis

Text fields are typically indexed by breaking the t ...

企业级搜索引擎Solr 第二章 Schema和文本分析(Schema and Text Analysis)[2]

文章转载自网易博客,原文地址:http://quweiprotoss.blog.163.com/blo ...

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

[译文] 恶意软件行为综述 - A View on Current Malware Behaviors

A View on Current Malware Behaviors Ulrich Bayer ...

Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing

http://spark-project.org/ 项目首页 http://shark.cs.berk ...

Scaling Pinterest - From 0 To 10s Of Billions Of Page Views A Month In Two Years

这篇文件写的非常好,推荐大家重温一下: http://highscalability.com/blog ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本