标签: queue

将String [] args值传递给另一个类

我的命令行输入为0 1 2,主代码如下所示.

public class AppleStoreRunner {
   public static void main(String [] args) {

        //maximum size of queue
        int qCapacity = Integer.parseInt(args[0]);

        //number of simulation hours
        int simHours = Integer.parseInt(args[1]);

        //average number of customers per hour
        int custPerHour = Integer.parseInt(args[2]);

        AppleStore myStore = new AppleStore(qCapacity, simHours, custPerHour);

        //Run simulation
        myStore.simulation();
        myStore.displayAcceptedCustomers();
        myStore.displayServedCustomers();
        myStore.displayWaitingCustomers();
        myStore.displayTurnAwayCustomers();

    }
}
Run Code Online (Sandbox Code Playgroud)

如何在以下类中调用输入的命令行参数,以便我可以在单独的扩展类中使用输入?下面的代码是我试图为3个输入数字创建变量的类.

public class AppleStore {

 int qCapacity;
 int simHours;
 int custPerHour;

/** Constructor 
* @param qCapacity The initial capacity of the queue to be …
Run Code Online (Sandbox Code Playgroud)

java string variables queue args

0
推荐指数
1
解决办法
667
查看次数

我的程序崩溃了

我的程序崩溃,我不知道为什么.我试图创建一个10个元素的队列.我的主要代码:

#include "queue.h"

int main(void){

Queue * queue;

queue = create_q(10);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的queue.h代码:

#ifndef QUEUE_H_
#define QUEUE_H_
#endif /* QUEUE_H_ */

#include <stdbool.h> /* for bool type */
#include <stdio.h> /* for standard IO support */
#include <stdlib.h> /* for malloc() and free() functions */

typedef struct patient { /* my structure */
    char name [20];
    char surname [20];
    int priority;
    struct patient * next; /* pointer to next node */
}Node;

typedef struct queue {
    Node * …
Run Code Online (Sandbox Code Playgroud)

c crash queue

0
推荐指数
1
解决办法
53
查看次数

工作线程只在队列中有东西时才消耗cpu

这是我想要做的.

我想拥有一个具有队列并启动线程的对象.另一个线程可以通过执行object.addWork(work)来推送到该队列;

这会将工作推入队列并在线程休眠时唤醒它.然后,线程对队列中的每个对象执行工作,直到队列为空.

一旦队列为空并且不再剩余工作,该线程就会休眠并需要通过再次添加到队列来唤醒.

是否有一种线程安全的方式来制作这样的对象?

java queue multithreading

0
推荐指数
1
解决办法
43
查看次数

队列不是模板

我一直在使用C ++ STL创建代码。我想使用“队列”。因此,我编写了如下代码。但是,我遇到了“队列不是模板”错误。如您所见,我在“ Common.h”文件中编写了与队列(iostream,queue)相关的标头,并在“ DataQueue.h”文件中包含了“ Common.h”。但是,VS2013 IDE工具说“ queue m_deQueue”是错误的,因为queue不是模板。我不知道为什么..发生此错误。任何帮助表示赞赏!

//[Common.h]
#ifndef _COMMON_
#define _COMMON_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

//thread related headers
#include <Windows.h>
#include <process.h>

//socket related headers
#include <winsock.h>

#include <iostream>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

#endif


//[DataQueue.h]
#ifndef _QUEUE_
#define _QUEUE_

#include "SocketStruct.h"
#include "Common.h"

class CDataQueue{
private:
    static CDataQueue*                  m_cQueue;
//  deque <ST_MONITORING_RESULT>        m_deQueue;
    queue <ST_MONITORING_RESULT>        m_deQueue;
    CRITICAL_SECTION                    m_stCriticalSection;

    CDataQueue();
    ~CDataQueue();

public:
    static CDataQueue* getDataQueue(){ …
Run Code Online (Sandbox Code Playgroud)

c++ queue stl

0
推荐指数
1
解决办法
1268
查看次数

我应该使用哪种STL来完成这项任务?

我需要一个必须添加/删除一些结构的队列,例如:

struct MyObject
{
  int offset;
  BYTE status, data1, data2;
  double beatPos;

  enum Status
  {
    isOff = 8,
    isOn = 9,
  };
}   
Run Code Online (Sandbox Code Playgroud)

当我.Add()是一个元素时,这个队列必须把元素放在正确的位置,因为这个beatPos值必须从下面(队列的顶部,即我要弹出的下一个元素)到上面(最后一个元素)排序我将从中提取).

我看到有std :: priority_queue,但我不确定我是否可以选择哪个是排序字段.

此外,一旦我在列表中添加了一些结构,我想删除第一个元素(例如)beatPos=1,567(例如,可能位于列表中间;不一定在开头).

有线索吗?

c++ queue stack list

0
推荐指数
2
解决办法
85
查看次数

laravel:恢复后得到工作ID

我如何才能进入laravel 5.2 的工作id
关于这个链接,我试过getJobId(),但不起作用.

当我使用dd()thers 获取日志时,当然id可能是受保护的.所以我无法访问它.

#job: {#459 +"id": 233 +"queue": "offers" +"payload": "{"job":"Illuminate\\Queue\\CallQueuedHandler@call","data":....}" +"attempts": 50 +"reserved": 0 +"reserved_at": null +"available_at": 1464615540 +"created_at": 1464615540 }

queue jobs laravel-5.2

0
推荐指数
1
解决办法
3147
查看次数

在调用remove()之前检查Queue是否还有什么

ConcurrentLinkedQueue在一组线程处理它们之前使用a 来排队元素:

public class AsyncActionQueue implements Serializable {

    ...

    private Queue<QueuedAction> queue;

    public AsyncActionQueue() {

        this.queue = new ConcurrentLinkedQueue<>();
    }

    ...

    private class QueueProcessor implements Runnable {

        private boolean isKilled = false;

        public void run() {

            while(!isKilled) {
                QueuedAction action = queue.remove();
Run Code Online (Sandbox Code Playgroud)

queue.remove()如果队列中没有更多元素,我认为会返回null,而是我得到一个NoSuchElementException.

这是一种情况,其中队列是单例,并且可以使用弹性数量的线程来清空它.在尝试删除之前,线程检查队列中是否有元素的最佳方法是什么?我应该检查是否queue.size() > 0,这意味着线程安全吗?

java queue multithreading thread-safety

0
推荐指数
1
解决办法
49
查看次数

Scala优先级队列不维持顺序

我希望这可以根据价格排序...

final case class Case(price: Int) {}
Run Code Online (Sandbox Code Playgroud)

但这实际上是一个更大的案例类,我从中删除了字段。我想这样排序...

val queue = PriorityQueue.empty[Case](Ordering.by((_: Case).price).reverse)
Run Code Online (Sandbox Code Playgroud)

^按降序排序。

现在我希望这种排序保持不变...

queue.enqueue(Case(price = 2))
println(queue.toString)

queue.enqueue(Case(price = 3))
println(queue.toString)

queue.enqueue(Case(price = 4))
println(queue.toString)

queue.enqueue(Case(price = 1))
println(queue.toString)

queue.enqueue(Case(price = 0))
println(queue.toString)
Run Code Online (Sandbox Code Playgroud)

但是我的输出没有在第四和第五行排序...

PriorityQueue(Case(2))
PriorityQueue(Case(2), Case(3))
PriorityQueue(Case(2), Case(3), Case(4))
PriorityQueue(Case(1), Case(2), Case(4), Case(3))
PriorityQueue(Case(0), Case(1), Case(4), Case(3), Case(2))
Run Code Online (Sandbox Code Playgroud)

而且,该foreach方法没有按顺序迭代...

queue.foreach{ q =>
  print(q + ", ")
}
Run Code Online (Sandbox Code Playgroud)

打印...

Case(0), Case(1), Case(4), Case(3), Case(2), 
Run Code Online (Sandbox Code Playgroud)

如何使我的队列保持降序排列?

queue scala priority-queue data-structures

0
推荐指数
1
解决办法
471
查看次数

将进度条添加到UIAlertController并显示更新

我尝试在我的应用程序上添加进度条.我找到了关于如何向UIAlertController添加进度条的问题?但它没有显示如何更新进度条.我简化了下面的代码,但没有更新进度条(只有在完成进度后才会显示).我看了什么?谢谢您的帮助.

override func viewDidLoad() {
    super.viewDidLoad()
    var topViewController = UIApplication.shared.delegate!.window!!.rootViewController!
    while (topViewController.presentedViewController != nil){
        topViewController = topViewController.presentedViewController!
    }
    DispatchQueue.main.async(execute: {
        let alert = UIAlertController(title: "downloading", message: "pls wait", preferredStyle: .alert)
        let progressBar = UIProgressView(progressViewStyle: .default)
        progressBar.setProgress(0.0, animated: true)
        progressBar.frame = CGRect(x: 10, y: 70, width: 250, height: 0)
        alert.view.addSubview(progressBar)
        topViewController.present(alert, animated: true, completion: nil)
        var progress: Float = 0.0
        repeat {
            DispatchQueue.global(qos: .background).async(execute: {
                progress += 0.01
                print (progress)
                DispatchQueue.main.async(flags: .barrier, execute: {
                    progressBar.setProgress(progress, animated: true)
                })
            }) …
Run Code Online (Sandbox Code Playgroud)

queue ios progress-bar uialertcontroller swift3

0
推荐指数
1
解决办法
3715
查看次数

为了在未加权图上实现Dijkstra的最短路径算法,使其在线性时间内运行,应使用哪种数据结构?

为了在未加权图上实现Dijkstra的最短路径算法以使其在线性时间内运行,要使用的数据结构为:

  1. 队列
  2. B树

我发现以下答案:

  1. 队列,因为我们可以使用广度优先搜索(BFS)算法在未加权图中找到单个源最短路径,该算法使用“队列”数据结构,时间为O(m + n)(即相对于顶点和边的数量呈线性) )

  2. 要在线性时间内实现它,就需要一个最小堆,因为如果我们在此处删除一个最小堆中的节点,则将不需要任何时间进行调整,因为所有r具有相同的权重,因此删除一个节点需要O(1)。 n-1个节点,它将是O(n)。

有人可以解释哪个是正确的答案吗?

algorithm queue stack graph dijkstra

0
推荐指数
1
解决办法
6064
查看次数