码迷,mamicode.com
首页 > 其他好文 > 详细

第十二天

时间:2016-05-11 23:26:17      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

特殊集合:

干草堆集合:

//Stack集合(干草堆,栈集合),先进后出(只有一个进出口),一个一个赋值,一个一个取值,按顺序
//.count(); 获取个数 .push();将元素推入集合 .pop();将元素弹出; .clear(); 清空
//定义方式
//Stack aa = new Stack();
//向集合内推送元素
//aa.Push(1);
//aa.Push(2);
//aa.Push(3);
//aa.Push(4);
//aa.Push(5);
//aa.Push(6);
//将元素弹出集合
//Console.Write(aa.Pop());//只要元素被弹出集合中就没有了
//Console.Write(aa.Peek());//只是弹出看一下 元素还在集合中

//清空集合
//aa.Clear();
//克隆
//aa.Clone();
//Stack bb = new Stack();
//bb = (Stack)aa.Clone();

 

队列集合:

//Queue 队列集合 先进先出(一个入口一个出口),一个一个的赋值,一个一个的取值
//Queue q = new Queue();
////进队列集合
//q.Enqueue(1);
//q.Enqueue(2);
//q.Enqueue(3);
//q.Enqueue(4);
//q.Enqueue(5);
////出队列集合
//q.Dequeue();//弹走第一个

////拿出来看一下不移除
//Console.WriteLine(q.Peek());

 

哈希表:

//Hashtable 哈希表 先进后出 一个一个赋值 但只能一起取值
//Hashtable ht = new Hashtable();
////添加元素
//ht.Add(0,"刘德华");
//ht.Add(1, "周杰伦");
//ht.Add(8, "周星驰");
//ht.Add(3, "张学友");
//ht.Add(4, "邓超");
//ht.Add(5, "陈赫");
//ht.Remove(5);//移除的是keys值以及valus值 括号里写的是keys值
////判断是否包含
//Console.WriteLine(ht.Contains(2));

////倒序打印,类似Stack集合

 


////利用枚举类型读取哈希表集合中的所有数据,像表格一样排序
//IDictionaryEnumerator id = ht.GetEnumerator();//读取哈希表中的数据 获取每一个keys值values值
////循环打印
//while (id.MoveNext())//移动到下一个key值与value值
//{
// Console.WriteLine(id.Key+"\t"+id.Value);
//}

 

例:

//输入班级人数,根据人数创建集合(arraylist)
//现存人名,紧跟着存他的分数
//打印出来表格,前面人名后面成绩

 1  Console.Write("请输入班级人数:");
 2             int a = int.Parse(Console.ReadLine());
 3             ArrayList aa = new ArrayList();
 4             for (int i = 0; i < (2 * a); i++)
 5             {
 6                 if (i % 2 == 0)
 7                 {
 8                     Console.Write("请输入名字:");
 9                     string b = Console.ReadLine();
10                     aa.Add(b);
11                 }
12                 else
13                 {
14                     Console.Write("请输入分数:");
15                     string b = Console.ReadLine();
16                     aa.Add(b);
17                 }
18             }
19             Console.WriteLine("姓名" + "\t" + "成绩");
20             for (int i = 0; i < (2 * a); i++)
21             {
22                 Console.Write(aa[i] + "\t");
23                 if (i % 2 != 0)
24                 {
25                     Console.WriteLine();
26                 }
27             }

 

第十二天

标签:

原文地址:http://www.cnblogs.com/mazhijie/p/5483804.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!