当前位置: 首页>>代码示例>>C++>>正文


C++ Queue::add方法代码示例

本文整理汇总了C++中Queue::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::add方法的具体用法?C++ Queue::add怎么用?C++ Queue::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Queue的用法示例。


在下文中一共展示了Queue::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {
  try {
    pis("zacatek");
    Queue<int> q;
    q.add(1); q.add(2); q.add(3); 
    pis("q1");
    Queue<int> q1 = q; 
    Queue<int> q2;
    q2=q;
    pis("q1konec");
    q.remove(); q.remove();
    for (int i=10; i<=35; i++)
      q.add(i);
    while (!q.empty()) {
        cout << q.front() << ' ';
        q.remove();
    }
    cout << endl;
    while (!q1.empty()) {
        cout << q1.front() << ' ';
        q1.remove();
    }
    cout << endl;
    while (!q2.empty()) {
        cout << q2.front() << ' ';
        q2.remove();
    }
    cout << endl;
  }
  catch (const char* s) {
    cout << "chyba: " << s << endl;
  }
  //system("PAUSE");
  return 0;
}
开发者ID:srna,项目名称:bi-pa2-122,代码行数:35,代码来源:main3b.cpp

示例2: breadthFirstTraversal

int BinarySearchTree :: breadthFirstTraversal (int number) const {
    
    Queue queue;
    BSTNode* current = root;
    queue.add(root);
    int count = 0;
    while (current != NULL) {
        
        //If there is right child, add it to queue
        if (current -> getLeft() != 0)
            queue.add(current -> getLeft());
        
        //If there is right child, add it to queue
        if (current -> getRight() != 0)
            queue.add(current -> getRight());
        
        queue.removeFromHead(current);
        if (current->getValue() == number) {
            return count;
        }
        current = getBSTNodeFromQueue(queue);
        count++;
    }
    return count;
}// end breadthFirstTraversal
开发者ID:Hitesh-jaarwis,项目名称:DFS,代码行数:25,代码来源:main.cpp

示例3: main

int main() {
  try {
    Queue<int> q;
    q.add(1); q.add(2); q.add(3); 
    q.remove(); q.remove(); q.remove();
    for (int i=10; i<=28; i++)
      q.add(i);
    Queue<int> r = q;
    while (!q.empty()) {
        cout << q.front() << ' ';
        q.remove();
    }
    cout << endl;
    while (!r.empty()) {
        cout << r.front() << ' ';
        r.remove();
    }
    cout << endl;
  }
  catch (const char* s) {
    cout << "chyba: " << s << endl;
  }
  //system("PAUSE");
  return 0;
}
开发者ID:srna,项目名称:bi-pa2-122,代码行数:25,代码来源:main2.cpp

示例4:

vector<int> Graph::BFS(int x) {
	Queue Q;
	bool *visited = new bool[n+1];
	int i;
	vector<int> conComp;
	for (i = 1; i <= n; ++i)
	visited[i] = false;
	Q.add(x);
	visited[x] = true;
	//cout << "Breadth First Search starting from vertex ";
	//cout << x << " : " << endl;
	while (!Q.isEmpty()) 
	{
		int k = Q.get();
		//cout << k << " ";
		for (i = 1; i <= n; ++i)
		{
			if (isConnected(k, i) && !visited[i]) 
			{
				Q.add(i);
				visited[i] = true;
				conComp.push_back(i);

			}
		}
	}
	//cout << endl;
	delete [] visited;
	return conComp; // return connected components
}
开发者ID:Rventric,项目名称:textline,代码行数:30,代码来源:graph.cpp

示例5: connect

    public void connect(TreeLinkNode root) {
        if (root == null)
            return;
        Queue<TreeLinkNode> queue = new LinkedList<TreeLinkNode>();
        queue.add(root);
        queue.add(null);

        while (!queue.isEmpty()) {
            TreeLinkNode out = queue.remove();
            if (out != null) {
                out.next = queue.peek();
                if (out.left != null)
                    queue.add(out.left);
                if (out.right != null)
                    queue.add(out.right);
            } else {
                if (!queue.isEmpty()) {
                    queue.add(null);
                }

            }

        }

    }
开发者ID:xuqiang,项目名称:leetcode,代码行数:25,代码来源:populating-next-right-pointers-in-each-node-ii.cpp

示例6: minPath

void Graph::minPath(int start, int target) {
    Queue Q;
    int i, p, q;
    bool found;
    struct aux {
        int current, prev;
    };
    aux *X = new aux[n+1];
    int *Y = new int[n+1];
    bool *visited = new bool[n+1];
    for (i = 1; i <= n; ++i)
        visited[i] = false;
    Q.add(start);
    visited[start] = true;
    found = false;
    p = q = 0;
    X[0].current = start;
    X[0].prev = 0;
    while (!Q.isEmpty() && !found) {
        int k = Q.get();
        for (i = 1; i <= n && !found; ++i)
            if (isConnected(k, i) && !visited[i]) {
                Q.add(i);
                ++q;
                X[q].current = i;
                X[q].prev = p;
                visited[i] = true;
                if (i == target) found = true;
            }
        ++p;
    }
    cout << "The minimum length path from " << start;
    cout << " to " << target << " is : " << endl;
    p = 0;
    while (q) {
        Y[p] = X[q].current;
        q = X[q].prev;
        ++p;
    }
    Y[p] = X[0].current;
    for (q = 0; q <= p/2; ++q) {
        int temp = Y[q];
        Y[q] = Y[p-q];
        Y[p-q] = temp;
    }
    for (q = 0; q <= p; ++q)
        cout << Y[q] << " ";
    cout << endl;
    cout << "Length = " << q-1 << endl;
    delete [] visited;
    delete [] X;
    delete [] Y;
}
开发者ID:Decker108,项目名称:c-homework,代码行数:53,代码来源:bredden_forst_exempel2.cpp

示例7: ares_gethostbyname

void ares_gethostbyname(ares_channel channel,
                                     const char *name,
                                     int family,
                                     ares_host_callback callback,
                                     void *arg)
{
//	if( QueueManager::manager()->check_cache(name,callback,arg) )
//		return;
	Queue *q = (Queue *)channel;
	q->add(name,s3eTimerGetUTC()+5000,callback,arg);
	QueueManager::manager()->step(q);
/*	{
		// DEBUG
						hostent ent;
						//char *hostname = new char[current->first()->host.size()+1];
						//memcpy(hostname,current->first()->host.c_str(),current->first()->host.size());
						//hostname[current->first()->host.size()] = 0;
						//ent.h_name = hostname;
						ent.h_name = (char *)name;
						ent.h_length = 4;
						char *addr_list[2];
						char *aliases[1] = { NULL };
						s3eInetIPAddress result;
						s3eInetAton(&result,"78.40.184.246");
						addr_list[0] = (char*)&result;
						addr_list[1] = NULL;
						ent.h_addr_list = addr_list;
						ent.h_aliases = aliases;
						ent.h_addrtype = AF_INET;
						//current->first_done(ARES_SUCCESS,&ent);
						callback(arg,ARES_SUCCESS,0,&ent);
	}
*/
}
开发者ID:h1048576,项目名称:libcurl,代码行数:34,代码来源:fake-ares.cpp

示例8: addStudents

void addStudents(){
	ifs.getline(stream, 10);
	int numStudents = atoi(stream);
	totalNumStudents += numStudents;
	for (int i = 0; i < numStudents; ++i){
		ifs.getline(stream, 10);
		q.add(atoi(stream));
	}
}
开发者ID:austinthiel,项目名称:CPSC-350,代码行数:9,代码来源:main.cpp

示例9: main3

int main3() {
  try {
    Queue<int> q;
    q.add(1); q.add(2); q.add(3); q.remove(); q.remove();
    for (int i=10; i<=35; i++)
      q.add(i);
    while (!q.empty()) {
        cout << q.front() << ' ';
        q.remove();
    }
    cout << endl;
  }
  catch (const char* s) {
    cerr << "error: " << s << endl;
  }
  system("PAUSE");
  return 0;
}
开发者ID:srna,项目名称:bie-pa2-122,代码行数:18,代码来源:main3.cpp

示例10: streamInsertionOthersTest

void streamInsertionOthersTest() {
    Vector<int> v;
    v.add(14);
    v.add(42);
    cout << "Vector: " << v << endl;

    Stack<int> s;
    s.add(14);
    s.add(42);
    cout << "Stack: " << s << endl;

    Queue<int> q;
    q.add(14);
    q.add(42);
    cout << "Queue: " << q << endl;

    PriorityQueue<int> pq;
    pq.add(14, 1);
    pq.add(42, 2);
    cout << "PriorityQueue: " << pq << endl;

    Grid<int> grid;
    grid.resize(2, 2);
    grid.fill(14);
    cout << "Grid: " << grid << endl;

    Map<string, Vector<int>> map;
    map.add("corfu", v);
    cout << "Map<string, Vector>: " << map << endl;

    HashMap<Stack<int>, Vector<int>> hashmap;
    hashmap.add(s, v);
    cout << "Map<Stack, Vector>: " << hashmap << endl;

    Set<int> set;
    set.add(14);
    set.add(42);
    cout << "Set: " << set << endl;

    HashSet<Set<int>> hashset;
    hashset.add(set);
    cout << "HashSet<Set>: " << hashset << endl;

    Graph<DumbNode, DumbEdge> graph;
    graph.addNode("a");
    graph.addNode("b");
    graph.addNode("c");
    graph.addNode("d");
    graph.addNode("e");
    graph.addArc("a", "b");
    graph.addArc("a", "d");
    graph.addArc("b", "c");
    graph.addArc("b", "d");
    graph.addArc("c", "b");
    graph.addArc("c", "e");
    cout << "Graph: " << graph << endl;
}
开发者ID:zmukwa,项目名称:stanford-whittier-cpplib,代码行数:57,代码来源:streamInsertionTests.cpp

示例11: main

int main() {
    Queue x;
    x.add("George").add("Washington").add("was").add("here.");
    cout <<endl;

    // x.add("BREAK!");

    x.remove();
    x.add("NOT!");
    cout <<endl;
    x.remove();
    x.add("Just kidding.");
    cout <<endl;
    x.remove();
    x.add("But seriously.");
    cout <<endl;
    x.remove();

    x.remove();
    x.remove();
    x.add("Would a man joke?").add("Or would he choke?");
    x.remove();
    x.add("How crazy is Hollywood?");
    x.remove();
    x.remove();

    x.remove();

    return 0;
} //main()
开发者ID:shiftf8,项目名称:cs536,代码行数:30,代码来源:h4.queue.cpp

示例12: main

int main(){
    Queue a = Queue();
    a.add("a");
    cout << a.getUsed() << endl;
    a.add("b");
    a.add("c");
    a.add("d");
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    cout << a.getUsed() << endl;
    a.add("e");
    a.add("f");
    a.add("break");
    cout << a.getUsed() << endl;
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    a.add("fake");
    cout << a.getUsed() << endl;
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    cout << a.remove() << endl;
    cout << a.getUsed() << endl;
    
    //system("pause");
    return 0;
} //main()
开发者ID:shiftf8,项目名称:cs536,代码行数:27,代码来源:labex7.cpp

示例13: BFS

void Graph::BFS(int x) {
    Queue Q;
    bool *visited = new bool[n+1];
    int i;
    for (i = 1; i <= n; ++i)
        visited[i] = false;
    Q.add(x);
    visited[x] = true;
    cout << "Breadth First Search starting from vertex ";
    cout << x << " : " << endl;
    while (!Q.isEmpty()) {
        int k = Q.get();
        cout << k << " ";
        for (i = 1; i <= n; ++i)
            if (isConnected(k, i) && !visited[i]) {
                Q.add(i);
                visited[i] = true;
            }
    }
    cout << endl;
    delete [] visited;
}
开发者ID:Decker108,项目名称:c-homework,代码行数:22,代码来源:bredden_forst_exempel2.cpp

示例14: main

int main(){
  char str[5][10]={
    "one", "two", "three", "four", "five"
  };
  char s[100];
  Queue q;
  int i;
  for(i=0;i<5;i++){
    q.add(str[i]);
  }

  while(!q.isEmpty()){
    q.remove(s);
    std::cout<<s<<std::endl;
  }

  return 0;
}
开发者ID:avoin,项目名称:20132notes,代码行数:18,代码来源:queuetester.cpp

示例15: action

void DataUpload::action() const {
// Make the xml files to upload
	string name("/tmp/data.");
	time_t now = time(0);
//	struct tm * mytm = localtime(&now);
//	char buf[20];
	
	// Implement purge_to:
	journal.purge(var.purgeTo);

	char buf[20];
	if (conf.getSiteId() < 0)		// Treat negative siteid as MAC address instead
		strcpy(buf, getmac());
	else {
		snprintf(buf, sizeof(buf), "%d", conf.getSiteId());
	}
	name += buf;
	name += ".xml";
	DEBUG cerr << "DataUpload::action Got name as " << name << "\n";
	journal.xml(name.c_str());
	
	queue.add(new DataUpload(timeMod(var.dataUpload, 1)));
	var.lastUpload = now;
	
	// Call send.sh
	string command(conf.serverComms);
	command += " ";
	command += buf;
	command +=" ";
	command += conf.serverUrl;
	command += " &";	// background it
	DEBUG cerr << "Invoking comms: '" << command;
	int retval = system(command.c_str());
	DEBUG cerr << "' Retval from system() is " << retval << endl;
	// Do a replace in case there is still a GetResponse in the queue
	queue.replace<GetResponse>(new GetResponse(now + 30));
}
开发者ID:Cybercontrolsystems,项目名称:mcp,代码行数:37,代码来源:action.cpp


注:本文中的Queue::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。