用C#语言编写:集合管理器
static void Main(string[] args)
{
List<int> numbers = new List<int>();
while (true)
{
#region 输出集合内容
Console.WriteLine("集合中现有内容如下:");
Console.WriteLine("===============================");
if (numbers.Count==0)
{
Console.WriteLine("集合中没有元素");
}
else
{
foreach (int item in numbers)
{
Console.Write(item + "\t");
}
Console.WriteLine();
}
Console.WriteLine("===============================");
#endregion
#region 提示菜单,并获取用户输入的菜单选项
Console.WriteLine("1.添加数据");
Console.WriteLine("2.删除数据");
Console.WriteLine("3.修改数据");
Console.WriteLine("4.升序排序");
Console.WriteLine("0.退出程序");
Console.Write("请输入(0-4):");
string input = Console.ReadLine();
#endregion
#region 根据用户输入的不同,做不同的处理
if (input =="0")
{
break;
}
else if(input == "1")
{
#region 添加数据
Console.Write("请输入要添加的数字:");
int num = int.Parse(Console.ReadLine());
numbers.Add(num);
#endregion
}
else if (input == "2")
{
#region 删除数据
Console.WriteLine("清输入你要删除的数据(只会删除第一个匹配项):");
int num = int.Parse(Console.ReadLine());
numbers.Remove(num);
#endregion
}
else if (input == "3")
{
#region 修改数据
if (numbers.Count == 0)
{
Console.Write("集合中没有任何程序可以修改,按回车键继续");
Console.ReadLine();
}
else
{
int maxIndex = numbers.Count - 1;
Console.Write("请输入要删除的下标(0-" + maxIndex + ")");
int index = int.Parse(Console.ReadLine());
if (index < 0 || index > maxIndex)
{
Console.WriteLine("输入错误,下标超出范围,按回车键继续");
Console.ReadLine();
}
else
{
Console.Write("请输入新的数据:");
int newnum = int.Parse(Console.ReadLine());
numbers[index] = newnum;
}
}
#endregion
}
else if (input == "4")
{
#region 升序排序
for (int i = 0; i < numbers.Count-1; i++)
{
for (int j = i+1; j < numbers.Count; j++)
{
if (numbers[i] > numbers[j])
{
int temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
}
}
#endregion
}
#endregion
//控制台清屏
Console.Clear();
}
}
用C#语言编写:集合管理器的更多相关文章
- WCF 服务的集合管理器的设计
今天是2019年2月1日,时间过得针对,马上就年底了,当前新年也离我们越来越近了.在此,我也祝福经常浏览我博客的朋友们“新年快乐.阖家欢乐”,来年有一个好彩头.在即将结束这一年之计,写今年的最后一片文 ...
- with上下文管理器
术语 要使用 with 语句,首先要明白上下文管理器这一概念.有了上下文管理器,with 语句才能工作. 下面是一组与上下文管理器和with 语句有关的概念. 上下文管理协议(Context Mana ...
- ZendFramework-2.4 源代码 - 关于服务管理器
// ------ 决定“服务管理器”配置的位置 ------ // 1.在模块的入口类/data/www/www.domain.com/www/module/Module1/Module.php中实 ...
- 实用算法系列之RT-Thread链表堆管理器
[导读] 前文描述了栈的基本概念,本文来聊聊堆是怎么会事儿.RT-Thread 在社区广受欢迎,阅读了其内核代码,实现了堆的管理,代码设计很清晰,可读性很好.故一方面了解RT-Thread内核实现,一 ...
- WPF技巧:通过代码片段管理器编写自己常用的代码模板提示效率
在写自定义控件的时候,有一部分功能是当内部的值发生变化时,需要通知控件的使用者,而当我在写依赖项属性的时候,我可以通过popdp对应的代码模板来完成对应的代码,但是当我来写属性更改回调的时候,却发现没 ...
- DVD管理器集合版
利用所学的集合写出的DVD管理系统,运用到了所学到集合基础. import java.text.ParseException; import java.text.SimpleDateFormat; i ...
- 运用集合来做一个DVD管理器(全代码)
package DVD;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Array ...
- python爬虫主要就是五个模块:爬虫启动入口模块,URL管理器存放已经爬虫的URL和待爬虫URL列表,html下载器,html解析器,html输出器 同时可以掌握到urllib2的使用、bs4(BeautifulSoup)页面解析器、re正则表达式、urlparse、python基础知识回顾(set集合操作)等相关内容。
本次python爬虫百步百科,里面详细分析了爬虫的步骤,对每一步代码都有详细的注释说明,可通过本案例掌握python爬虫的特点: 1.爬虫调度入口(crawler_main.py) # coding: ...
- 1.Cocos2d-x-3.2编写3d打飞机,粒子管理器代码
Cocos2d-x中的一个单例效果: #ifndef __Moon3d__ParticleManager__ #define __Moon3d__ParticleManager__ #inclu ...
随机推荐
- spring+mybatis+c3p0数据库连接池或druid连接池使用配置整理
在系统性能优化的时候,或者说在进行代码开发的时候,多数人应该都知道一个很基本的原则,那就是保证功能正常良好的情况下,要尽量减少对数据库的操作. 据我所知,原因大概有这样两个: 一个是,一般情况下系统服 ...
- 【html5】html5本地简单存储
html5本地简单存储 HTML5 提供了四种在客户端存储数据的新方法,即 localStorage .sessionStorage.globalStorage.Web Sql Database. 前 ...
- 从1.5K到18K,一个程序员的5年成长之路
原文地址:点击打开链接 168楼朋友批评的很有道理, 虚心接受. 我自己是开始学的时候已经错过了基础课的学习, 现在也是深受其苦的, 面临技术上的瓶颈, 需要花更多的时间补充这些知识. 希望看到此文的 ...
- Invalid property 'driver_class' of bean class
1.错误描述 INFO:2015-05-01 13:06:07[localhost-startStop-1] - Initializing c3p0-0.9.2.1 [built 20-March-2 ...
- Linux显示历史记录
Linux显示历史记录 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ history 1 uname -a 2 lsusb 3 df -h 4 ps -A 5 ...
- River Hopscotch POJ - 3258
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ...
- Crash CodeForces - 417B
During the "Russian Code Cup" programming competition, the testing system stores all sent ...
- iOS - GATT Profile 简介
1.引言 现在低功耗蓝牙(BLE)连接都是建立在 GATT (Generic Attribute Profile) 协议之上.GATT 是一个在蓝牙连接之上的发送和接收很短的数据段的通用规范,这些很短 ...
- GridView添加事件监听和常用属性解析
1. 使用流程 graph LR 准备数据源-->新建适配器 新建适配器-->绑定数据源 绑定数据源-->加载适配器 2. 常用属性 android:columnWidth:每一列的 ...
- Android中selector的使用
第一种方法(强烈推荐) 方法:selector做遮罩,原图做background. 我们做按钮的时候经常需要用两个图片来实现按钮点击和普通状态的样式,这就需要提供两种图片,而且每个分辨率下还有多套图片 ...