Collection类学习

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections; namespace Colloction
{
class Collection:CollectionBase
{
public void Add(Object item) { InnerList.Add(item); }
public void Remove(Object item) { InnerList.Remove(item); }
public void Clear(){InnerList.Clear();}
public int Count() { return InnerList.Count; } }
class Program
{
static void Main(string[] args)
{
Collection names = new Collection();
names.Add("");
names.Add("");
names.Add("");
names.Add("");
foreach (Object name in names) { Console.WriteLine(name); }
Console.WriteLine("总数量: "+names.Count());
names.Remove("");
Console.WriteLine("总数量: " + names.Count());
names.Clear();
Console.WriteLine("总数量: " + names.Count());
}
}
}

泛型

 static void Swap<T>(ref T val1,ref T val2)
{
T temp;
temp = val1;
val1 = val2;
val2 = temp;
}
static void Main(string[] args)
{
int num1 = ;
int num2 = ;
Swap<int>(ref num1, ref num2);
Console.WriteLine(num1);
}

测量时间

            DateTime startTime;
TimeSpan endTime;
startTime = DateTime.Now;
for (int i = ; i < ; i++)
;
endTime = DateTime.Now.Subtract(startTime);
Console.WriteLine(endTime.TotalSeconds);

高级版

       TimeSpan endTime;
for (int i = ; i < ; i++)
;
endTime = Process.GetCurrentProcess().TotalProcessorTime;
Console.WriteLine(endTime);

锯齿状数组

int[] Jan = new int[];
int[] Feb = new int[];
int[][] sales = new int[][]{Jan,Feb};

ArrayList

   static void Main(string[] args)
{
ArrayList grades = new ArrayList();
grades.Add();
grades.Add();
int position = grades.Add();
Console.WriteLine(position);//输出位置
grades.Insert(, );
string[] newNames = new string[] { "孙大海", "海大富" };
grades.InsertRange(, newNames);
foreach (object grade in grades)
Console.WriteLine(grade);
}

选择排序

       for (int i = ; i < ;i++)
{
int min = i; //每行选出一个最小的来跟头上交换
for(int j=i;j<;j++)
{
if (arr[j] < arr[min]) min = j;
}
if(min!=i)
{
int t = arr[min];
arr[min] = arr[i];
arr[i] = t;
}
}

冒泡排序

   for (int i = ; i < ; i++)//每次都拿第一个来冒泡 跑到不能跑的位置 回来再从第一个泡
{
for (int j = ; j < - i; j++)
{
if (arr[j] > arr[j + ])
{
int t = arr[j];
arr[j] = arr[j + ];
arr[j + ] = t;
}
}
}

二分查找

        public static int binSearch(int value)
{
int upperBound, lowerBound, mid;
upperBound = arr.Length - ;
lowerBound = ;
while(lowerBound<=upperBound)
{
mid = (lowerBound + upperBound) / ;
if (arr[mid] == value) return mid;
else
{
if (value < arr[mid])
upperBound = mid - ;
else
lowerBound = mid + ;
}
}
return -;
}
public static int RbinSearch(int value,int lower,int upper)
{
if (lower > upper) return -;
else
{
int mid = (upper + lower)/;
if (value < arr[mid])
{
return RbinSearch(value, lower, mid - );
}
else if (value == arr[mid]) return mid;
else
return RbinSearch(value, mid + , upper);
}
}

class CStack
{
private ArrayList List;
private int p_index;
public CStack()
{
List = new ArrayList();
p_index=-;
}
public int count{get{return List.Count;}}
public void push(object item)
{
List.Add(item);
p_index++;
}
public object pop()
{
object obj = List[p_index];
List.RemoveAt(p_index);
p_index--;
return obj;
}
public object peek()
{
return List[p_index];
}
static void Main(string[] args)
{
CStack alist = new CStack();
string word = "sees";
alist.push(word[]);
alist.push(word[]);
alist.push(word[]);
alist.push(word[]);
Console.WriteLine(alist.peek()); }
}

队列

//写入数据到Queue中
Queue q = new Queue();
for (int i = ; i < ; i++)
{
q.Enqueue(i);
} //循环输出Queue所有数据
Console.WriteLine("开始输出Queue数据");
while (q.Count > )
{
Console.WriteLine(q.Dequeue());
} //-------------------------------------分割线------------------------------------// //写入数据到Stack中
Stack s = new Stack();
for (int i = ; i < ; i++)
{
s.Push(i);
} //循环输出所有Stack数据
Console.WriteLine("开始输出Stack数据");
while (s.Count > )
{
Console.WriteLine(s.Pop());
}

C#数据结构学习的更多相关文章

  1. 算法设计和数据结构学习_5(BST&AVL&红黑树简单介绍)

    前言: 节主要是给出BST,AVL和红黑树的C++代码,方便自己以后的查阅,其代码依旧是data structures and algorithm analysis in c++ (second ed ...

  2. 数据结构学习之字符串匹配算法(BF||KMP)

    数据结构学习之字符串匹配算法(BF||KMP) 0x1 实验目的 ​ 通过实验深入了解字符串常用的匹配算法(BF暴力匹配.KMP.优化KMP算法)思想. 0x2 实验要求 ​ 编写出BF暴力匹配.KM ...

  3. 数据结构学习之栈求解n皇后问题

    数据结构学习之栈求解n皇后问题 0x1 目的 ​ 深入掌握栈应用的算法和设计 0x2 内容 ​ 编写一个程序exp3-8.cpp求解n皇后问题. 0x3 问题描述 即在n×n的方格棋盘上,放置n个皇后 ...

  4. 1.基础: 万丈高楼平地起——Redis基础数据结构 学习记录

    <Redis深度历险:核心原理和应用实践>1.基础: 万丈高楼平地起——Redis基础数据结构 学习记录http://naotu.baidu.com/file/b874e2624d3f37 ...

  5. ES6中Map数据结构学习笔记

    很多东西就是要细细的品读然后做点读书笔记,心理才会踏实- Javascript对象本质上就是键值对的集合(Hash结构),但是键只能是字符串,这有一定的限制. 1234 var d = {}var e ...

  6. linux内核数据结构学习总结

    目录 . 进程相关数据结构 ) struct task_struct ) struct cred ) struct pid_link ) struct pid ) struct signal_stru ...

  7. 十五分钟介绍 Redis数据结构--学习笔记

    下面是一个对Redis官方文档<A fifteen minute introduction to Redis data types>一文的翻译,如其题目所言,此文目的在于让一个初学者能通过 ...

  8. 邓俊辉数据结构学习-7-BST

    二叉搜索树(Binary-Search-Tree)--BST 要求:AVL树是BBST的一个种类,继承自BST,对于AVL树,不做太多掌握要求 四种旋转,旋转是BBST自平衡的基本,变换,主要掌握旋转 ...

  9. ES6中map数据结构学习

    在项目中遇到一个很恶心的需求,然后发现ES6中的map可以解决,所以简单学习了一下map. Javascript的Object本身就是键值对的数据结构,但实际上属性和值构成的是“字符串-值”对,属性只 ...

  10. GJM : 数据结构学习笔记

    --------------------------数据结构 --------------------数据结构分 线性数据结构给非线性数据结构 数据和结合 线性表(顺序存储方式)特点:有且仅有一个开始 ...

随机推荐

  1. Jdk1.6编译,1.7执行,1.7中没有需要的类,为何不会报错

      今天发现一个非常奇怪的问题   import sun.misc.BASE64Decoder; 我在本地引入了jdk1.6中的包,编译也用1.6没问题,但是实际上jdk1.7并没有这个包.在Linu ...

  2. The Python Challenge 谜题全解(持续更新)

    Python Challenge(0-2) The Python Challengehttp://www.pythonchallenge.com/ 是个很有意思的网站,可以磨练使用python的技巧, ...

  3. Hdoj 4540.威威猫系列故事——打地鼠 题解

    Problem Description 威威猫最近不务正业,每天沉迷于游戏"打地鼠". 每当朋友们劝他别太着迷游戏,应该好好工作的时候,他总是说,我是威威猫,猫打老鼠就是我的工作! ...

  4. 自学Zabbix4.0之路

    自学Zabbix4.0之路 01 Centos7安装Zabbix4.0步骤 02 Centos7下Zabbix3.4至Zabbix4.0的升级步骤 03 Zabbix4.0添加cisco交换机基本监控 ...

  5. table用模板生成的问题

    在使用<template></template>存放HTML模板标记时,发现一个烦人的问题,表格不行. <template> <table> <t ...

  6. 简单使用TFS管理源代码

    今天研究使用了一下TFS,主要是想管理源代码.不涉汲团队管理. 使用环境W10专业版  / VS2017 社区版 / SQLSERVER2016  / TFS2017 EXPRESS版本 1.下载和安 ...

  7. 在centos7下用http搭建配置svn服务

    应用场景:SVN是Subversion的简称,是一个开放源代码的版本控制系统. 安装环境:centos7  //已关闭 Selinux和 Firewall 配置步骤: 1. 安装HTTP和SVN相关软 ...

  8. Python学习day4 数据类型Ⅱ(列表,元祖)

    day4 知识补充&数据类型:列表,元祖 1.知识补充 1.编译型/解释型 编译型:在代码编写完成之后编译器将其变成另外一个文件教给你算计执行. 代表语言:Java,c,c++ ,c#, Go ...

  9. Apache Beam实战指南 | 手把手教你玩转KafkaIO与Flink

    https://mp.weixin.qq.com/s?__biz=MzU1NDA4NjU2MA==&mid=2247492538&idx=2&sn=9a2bd9fe2d7fd6 ...

  10. poj3630 Phone List

    spy on一下,发现是trie裸题,结果一交就T... 然后把cin改成scanf就A了... trie的空间一定要开足,要不然RE #include <cstdio> #include ...