设计好的集团网站建设多少钱建筑模板工
设计好的集团网站建设多少钱,建筑模板工,100块钱开发网站,融资网站建设广度优先算法#xff08;Breadth-First Search#xff09;是在图和树领域的搜索方法#xff0c;其核心思想是从一个起始点开始#xff0c;访问其所有的临近节点#xff0c;然后再按照相同的方式访问这些临近节点的节点#xff0c;这种访问方式类似涟漪泛起#xff0c;一…广度优先算法Breadth-First Search是在图和树领域的搜索方法其核心思想是从一个起始点开始访问其所有的临近节点然后再按照相同的方式访问这些临近节点的节点这种访问方式类似涟漪泛起一层一层的扩散。
广度优先算法解决的问题
从A点出发有没有一条路径可以到达B点如果有的话能不能找到最短的路径。图/树的遍历
广度优先算法的实现C
要遍历的图结构 using System;
using System.Collections;
using System.Reflection;
using UnityEngine;namespace Framwork
{/// summary/// Playerprefs 存储类/// /summarypublic class PlayerPrefsManager{private static PlayerPrefsManager instancenew PlayerPrefsManager();public static PlayerPrefsManager Instance instance;private PlayerPrefsManager(){}/// summary/// 存取数据的方法/// /summary/// param nameobj数据实体/param/// param namename数据名称/parampublic void SaveData(object data, string keyName){Type type data.GetType();FieldInfo[] infos type.GetFields();string tempKeynull;FieldInfo tempInfo null;for (int i 0; i infos.Length; i){//获取数据数据类型tempInfo infos[i];Debug.Log(TypestempInfo);//类的名字类的类型 数据内容名字数据类型//作为存储的keyName键tempKey keyName _ type.Name _ tempInfo.Name _ tempInfo.FieldType.Name;SaveValue(tempInfo.GetValue(data),tempKey);}//进行值的获取//tempInfo.GetValue(data);PlayerPrefs.Save();}/// summary/// 读取数据的类型/// /summary/// param nametype要读取的数据类型/param/// param namename要读取的数据名称/param/// returns返回数据实体/returnspublic object LoadData(Type type, string name){//获取数据中的类型FieldInfo[] infos type.GetFields();//创建存储数据信息的实体object data Activator.CreateInstance(type);string tempName null;FieldInfo tempInfo null;for (int i 0; i infos.Length; i){tempInfo infos[i];//数据结构中的数据名称tempName name _ type.Name _ tempInfo.Name_tempInfo.FieldType.Name;//数据结构中的数据名称类型//装载的容器 容器中的数据 //进行数据装载tempInfo.SetValue(data,LoadValue(tempInfo.FieldType,tempName));}return data;}/// summary/// 进行具体的类型数据的存储/// /summary/// param namedata/param/// param namekeyName/paramprivate void SaveValue(object value, string keyName){Type fieldType value.GetType();if (fieldType typeof(int)){Debug.Log(存储intvalue);PlayerPrefs.SetInt(keyName,(int)value);}else if (fieldType typeof(float)){Debug.Log(存储floatvalue);PlayerPrefs.SetFloat(keyName,(float)value);}else if (fieldType typeof(string)){Debug.Log(存储stringvalue);PlayerPrefs.SetString(keyName,value.ToString());}//对于List存储的设置//根据存储的字段类型和IList是否是父子关系else if(typeof(IList).IsAssignableFrom(fieldType)){//父类装子类IList listvalue as IList;//存储元素数量PlayerPrefs.SetInt(keyName,list.Count);Debug.Log(存储List长度为list.Count);int index 0;foreach (var obj in list){//存储list列表中元素内容//命名形式是 list名字索引编号//递归调用存储SaveValue(obj,keyNameindex);index;}}else if (typeof(IDictionary).IsAssignableFrom(fieldType)){IDictionary dictionary value as IDictionary;//存储数据个数PlayerPrefs.SetInt(keyName,dictionary.Count);Debug.Log(存储Dic长度为dictionary.Count);int index 0;foreach (var key in dictionary.Keys){//存储键SaveValue(key,keyName_key_index);//存储值 SaveValue(dictionary[key],keyName_value_index);index;}}//自定义数据类型的存储 进行解析else {SaveData(value,keyName);}}private object LoadValue(Type type, string name){if (type typeof(int)){return PlayerPrefs.GetInt(name,0);}else if (type typeof(float)){return PlayerPrefs.GetFloat(name,0.0f);}else if (type typeof(string)){return PlayerPrefs.GetString(name,);}else if (typeof(IList).IsAssignableFrom(type)){//读取列表int count PlayerPrefs.GetInt(name);IList tempListActivator.CreateInstance(type) as IList;for (int i 0; i count; i){//获取List中存储元素的类型 type.GetGenericArguments()[0]tempList.Add(LoadValue(type.GetGenericArguments()[0],namei));}return tempList;}else if (typeof(IDictionary).IsAssignableFrom(type)){//进行对字典的读取int count PlayerPrefs.GetInt(name);IDictionary tempDictionaryActivator.CreateInstance(type) as IDictionary;for (int i 0; i count; i){tempDictionary.Add(LoadValue(type.GetGenericArguments()[0], name _key_ i),LoadValue(type.GetGenericArguments()[1], name _value_ i));}return tempDictionary;}else{//读取自定义类成员的设置return LoadData(type, name);}}}
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/90477.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!