Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,942 questions

51,880 answers

573 users

How to copy queue to another queue in C#

2 Answers

0 votes
using System;
using System.Collections.Generic;
                     
public class Program
{
    public static void PrintQueue(Queue<string> q) {
       foreach(string s in q) {
           Console.WriteLine(s);
       }
    }
    public static void Main()
    {
        Queue<string> q = new Queue<string>();
         
        q.Enqueue("c#");
        q.Enqueue("vb.net");
        q.Enqueue("java");
        q.Enqueue("php");
        q.Enqueue("c++");
         
		string[] arr = new string[q.Count * 2];
        q.CopyTo(arr, q.Count);

        Queue<string> q2 = new Queue<string>(arr);
		
		// Remove all the null elements 
		for (int i = 0; i < q.Count; i++)
			q2.Dequeue();
		
		PrintQueue(q2);
    }
}
 
 
/*
run:
 
c#
vb.net
java
php
c++
 
*/

 



answered May 5, 2020 by avibootz
0 votes
using System;
using System.Collections.Generic;
                     
public class Program
{
    public static void PrintQueue(Queue<string> q) {
       foreach(string s in q) {
           Console.WriteLine(s);
       }
    }
    public static void Main()
    {
        Queue<string> q = new Queue<string>();
         
        q.Enqueue("c#");
        q.Enqueue("vb.net");
        q.Enqueue("java");
        q.Enqueue("php");
        q.Enqueue("c++");
 
		Queue<string> q2 = new Queue<string>(q);
		
		PrintQueue(q2);
    }
}
 
 
/*
run:
 
c#
vb.net
java
php
c++
 
*/

 



answered May 5, 2020 by avibootz

Related questions

1 answer 140 views
140 views asked Apr 21, 2020 by avibootz
1 answer 162 views
1 answer 143 views
143 views asked Aug 15, 2022 by avibootz
1 answer 110 views
2 answers 177 views
177 views asked Jan 6, 2017 by avibootz
1 answer 144 views
1 answer 155 views
...