
正文
vb.net数组先进先出 vb将数组中的数逆序存放
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
求用vbnet 实现先进先出即队列得源代码
VB.Net中vb.net数组先进先出的队列类在System.Collections.Generic命名空间中vb.net数组先进先出,名字叫Queue,是一个泛型类。
实例化该类vb.net数组先进先出:
Dim myQueue As QueueInt32
myQueue = new QueueInt32();
然后可以通过Queue中的Enqueue和Dequeue函数进行入队出队操作:
With myQueue
.Enqueue(1)
.Enqueue(2)
.Enqueue(3)
.Enqueue(4)
.Enqueue(5)
End With
For i = 0 To 5 Step 1
Console.WriteLine(myQueue.Dequeue())
Next i
显示结果:
1
2
3
4
5
相关问答
Q1: VB.NET 找出数组中相同的元素,并按相同元素排序到另外一个数组中。
先把strA排序,
ind = 2
if len(strA) = 0 then return
strB(1) = strA(1)
for each s in strA
if (strA(ind) strA(ind - 1) then
count = 0
strB(ind) = strA(ind)
else
strB(ind) = strA(ind - 1)
end if
ind = ind + 1
next s
vb语法忘了。。。大概是这么个意思吧。。。。 排序N LOG N,后面是线性的N,所以总共是NLOGN
Q2: vb.net 对象数组
你只是定义了一个对象,类而已
首先要给对象设置变量,这个还不是数组
Public class As Single的class 应该是关键字请换一个名字
Dim KidsX(1 to 100) as kids
KidsX(1).classx=1
KidsX(1).grade=1
KidsX(1).name=”张某"
KidsX(2).classx=1
KidsX(2).grade=2
KidsX(2).name=”王某"
……
Q3: VB.net 数组怎么按任意元素的顺序排序输出
你直接传一个数组进去,而且是一个结构体数组,array.sort怎么知道根据结构中的哪一个属性进行排序?放一个c#的代码你看看,VB和C#很相似的
class Program
{
static void Main(string[] args)
{
People[] p = new People[3]
{
new People{name="张三"},
new People{name="李四"},
new People{name="张二名"}
};
//重点传一个实现了IComparer接口的类进去,告诉Array.Sort怎么排序
Array.Sort(p, new PeopleCompare());
foreach (var item in p)
{
Console.WriteLine(item.name);
}
Console.ReadKey();
}
}
//People结构体,换成类一样的
public struct People
{
public string name { get; set; }
}
//实现了IComparer接口的类
public class PeopleCompare : IComparer
{
public int Compare(object x, object y)
{
People p1 = (People)x ;
People p2 = (People)y;
return p1.name.CompareTo(p2.name);
}
}
vb.net数组先进先出的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb将数组中的数逆序存放、vb.net数组先进先出的信息别忘了在本站进行查找喔。






