- 时间:2021-02-11 22:57 编辑:李星辰 来源:蚂蚁资源 阅读:131
- 扫一扫,手机访问
摘要:大家好,今天给大家介绍关于list源码(list实现原理)的相关内容,详细讲解求一个C++linklist源代码 越简单越好。初学者伤不起啊,java中ArrayList的源代码是什么,C语言中的list是指什么求一个简单的list代码等,希望可以帮助到您。
求一个C++linklist源代码 越简单越好。初学者伤不起啊,以下单个代码列表,包括用于参考的定义,创建,输出,删除等,使用名称{int数据;结构节点* pnext;节点; / *创建n个元素lin表* / node * creatlink(int n){int i;节点* Phead,* P,* Q; if(npnext = null; printf(“\ n创建的链接列表:请输入%d整数:”,n); scanf(“%d”,&(q->数据)); for(i = 0; ipnext = p; q = p; q-> pnext = null; scanf(“%d”,&(q-> data));}}}}} / *删除链接* / int deletelink(节点*&phead){节点* p,* q;如果(null == phead)返回0; q = phead; p = q-> pnext; printf“\ n删除链接列表”);而(null!= p){free(q) ; q = p; p = q-> pnext;}自由(q); phead = null;返回0;} / *输出链接列表* / int printlink(节点* p,* q; printf(“\ n输出链接列表:“);如果(null == phead){printf(“空名单!”);返回0; q = phead; p = q-> pnext;虽然(null!= p){printf(“%d - >”,q->数据); Q = P; p = q-> pnext;} printf(“%d)”,q->数据);返回0;} / *插入列表,在第一位置插入元素元素* / int插入物链接(节点* phead,int n,int元素){int i;节点* p,* q;如果(null == phead)返回0; q = phead; p = q-> pnext;我= 1; printf(“\ n插入链接列表,插入元素%d。”,n,元素);而(ipnext; i ++; p->); ipnext; I ++; p-> pnext = q-> pnext; q-> pnext = p;}}}}返回0;} / *获取lin表的第n个位置的元素保存在元素* /插入者中(节点* phead,int n,int&元素){int i;节点* p,* q;如果(null == phead)返回0; q = phead; p = q-> pnext;我= 1;而(ipnext; i ++;}如果(我是dat一个; printf)n获取链列表,第一d位置的元素:%d“,n,元素);}返回0;} / *单向链表演示* / int main(){node * head; head = cretlink(6); printlink(head); deletelink(head); printlink(head);返回0;}
java中ArrayList的源代码是什么,包java.util;公共类ArrayList
扩展了AbstractList illiments列表,randuccess,cloneable,java.io.serializable {私有静态最终长SerialVersionUID = 8683452581122892189L; / ** *将ArrayList的元素存储到哪个阵列缓冲区* ArrayList的容量是此阵列缓冲区* /私分瞬态E [] ElementData的长度; .. / ** * ArrayList的大小(它包含的元素数量* *。 @serial * /私有int尺寸; / ** *构造具有指定初始容量的空列表* * @param initialCapacity列表的初始容量* @exception IllegalAlgumentException如果指定的初始容量*为负。* /公共arraylist(int initialcapacity){super(); if(initialCapacity < 0) throw new IllegalArgumentException("Illegal Capacity: "+ initialCapacity);this.elementData = (E[])new Object[initialCapacity]; } public ArrayList() {this(10); } public ArrayList(Collection extends E> c){size = c.size(); //允许10%的生长int容量=(int)math.min((size)* 110l)/ 100,integer.max_value); ElementData =(e [])c.toArray(新对象[容量]);} public void trimtosize(){modcount ++; int oldcapacity = ElementData.Length; if(size < oldCapacity) { Object oldData[] = elementData; elementData = (E[])new Object[size]; System.arraycopy(oldData, 0, elementData, 0, size);} } public void ensureCapacity(int minCapacity) {modCount++;int oldCapacity = elementData.length;if (minCapacity > odelcapacity){object olddata [] = ElementData; int newcapacity =(oldcapacity * 3)/ 2 + 1; if(newcapacity < minCapacity)newCapacity = minCapacity; elementData = (E[])new Object[newCapacity]; System.arraycopy(oldData, 0, elementData, 0, size);} } public int size() {return size; } public boolean isEmpty() {return size == 0; } public boolean contains(Object elem) {return indexOf(elem) > = 0;} public int indexof(对象elem){if(elem == null){for(int i = 0; i < size; i++)if (elementData[i]==null) return i;} else { for (int i = 0; i < size; i++)if (elem.equals(elementData[i])) return i;}return -1; } public int lastIndexOf(Object elem) {if (elem == null) { for (int i = size-1; i > = 0; i - )if(元素数据[i] = = null)返回i;} else {for(int i = size-1; i> = 0; i- - )如果(elem.equals(experteddata [i]))返回i;} return -1;}公共对象clone(){try {arraylist v =(arraylist )super.clone(); v.elementdata =(e [])新对象[size]; system.arraycopy(exportdata,0,v.elementdata ,0,尺寸); v。modcount = 0; return v;} catch(clonenotsupportedException e){//这不应该发生,因为我们是Cloneable抛出新的evertError();}} publice object [] toarray(){object []结果=新对象[size]; system.arraycopy(元素数据,0,结果,0,大小);返回结果;公共 t [] toArray(t [] a){if(a.length < size) a = (T[])java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size);System.arraycopy(elementData, 0, a, 0, size); if (a.length >大小)a [size] = null;返回一个;} //位置访问操作公共E get(索引){rangecheck(索引);返回ElementData [index];} public e set(index,e元素){rangecheck(索引); oldvalue = ElementData [Index]; ElementData [index] =元素; Rovero OldValue;}公共布尔添加(InsureCapacity(Size + 1); //递增Modcount !! ElementData [size ++] = o;返回true;}公共void添加(int index,电子元素){if(index> size ||索引< 0) throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);ensureCapacity(size+1); // Increments modCount!!System.arraycopy(elementData, index, elementData, index + 1, size - index);elementData[index] = element;size++; } public E remove(int index) {RangeCheck(index);modCount++;E oldValue = elementData[index];int numMoved = size - index - 1;if (numMoved > 0)System.ArrayCopy(ElementData,Index + 1,ElementData,Index,NumMoved); ElementData [ - size] = null; //让GC进行WorkReturn OldValue;}公共布尔删除(对象O){if(o == null){for(int index = 0; index < size; index++)if (elementData[index] == null) { fastRemove(index); return true;}} else { for (int index = 0; index < size; index++)if (o.equals(elementData[index])) { fastRemove(index); return true;} }return false; } private void fastRemove(int index) { modCount++; int numMoved = size - index - 1; if (numMoved > 0)system.arraycopy(exportData,index + 1,ElementData ,索引,麻木); ElementData [ - size] = null; //让GC执行其工作} public void clear(){modcount ++; //让GC执行它的工作(int i = 0; i < size; i++) elementData[i] = null;size = 0; } public boolean addAll(Collection extends E> c){object [] a = c.toArray(); int numnew = a.length; EnsureCapacity(尺寸+ numnew); //递增modcount system.arraycopy(a,0,元素数据,大小,numnew); size + = numnew;返回numnew! = 0;}公共布尔addall(int index,collection extends E> c){if(index> size ||索引< 0) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);Object[] a = c.toArray();int numNew = a.length;ensureCapacity(size + numNew); // Increments modCountint numMoved = size - index;if (numMoved > 0)system.arraycopy(exportdata,index,ElementData,索引+ numnew,nummoved); SY.stem.arraycopy(a,0,元素数据,索引,numnew); size + = numnew;返回numnew = 0 ;!}受保护的void removerange(int fromindex,int toindex){modcount ++; int nummoved = size - toindex; system.ArrayCopy(ElementData,ToIndex,ElementData,fromIndex,Nummoved); //让GC做其努力newsize = size - (toindex-fromindex while(size!= newsize)元素数据[ - size] = null;}私有void rancecheck(int index){if(index> = size)抛出新的indeexoutofboundsexception( “索引:”+索引+“,大小:”+大小“;私有void writeObject(java.io.ObjectOutputStream s)抛出java.io.ioexception {int perminermodcount = modcount; //写出元素计数,以及任何隐藏stuffs.default(); //写出数组长度s.writeint(exportedata.length); //以正确的顺序写出所有元素.for(int i = 0; i C语言中的list是指什么求一个简单的list代码,C语言没有列表列表是在C ++中的一个类别使用C ++来检查来自Internet,有许多应用程序。
责任编辑(李星辰)
以上就是关于**list源码,list实现原理**的全部内容,了解更多请关注蚂蚁资源网。
- 萨满祭司
- 做列表页的模板5.0的LIST文件代码怎么和教程的不一样啊!~,建议楼主,可以直接复制template/default/list.htm文件里面对应的代码
- 2021-02-11 22:57:38
- 区块链
- List<Object> list = new LinkedList<Object>(); 泛型可以根据实际来定义
- 2021-02-11 22:57:38
- 世源网络科技
- 懒得写。。。做个共有基类,比如:class object{// 能提为共有的就提炼出来};使用基类保存就好了,反正子类型基类转化,直接转化就好了;list test_list;使用的话,只要你知道第几个具体是什么类,你转换回来就好了。Student* student = dynamatic_cast(test_list_iterator);Teacher* teacher = dynamatic_cast(test_list_iterator);
- 2021-02-23 16:00:01