博客
关于我
线型表的顺序存储结构----顺序表(学习笔记)
阅读量:489 次
发布时间:2019-03-07

本文共 1816 字,大约阅读时间需要 6 分钟。

定义一长度为80的链表,表中元素从1-80,实现对表的增、删、清0功能。

插入算法简介:

1 判断插入位置是否合理
2 把插入位置后面的元素向下移一位
3 把元素插到指定位置
4 链表长度加1

删除算法简介:

1 判断删除位置是否合理
2 把删除位置后面的元素向上移一位
3 链表长度减1

查找算法简介:

1 用for循环和equals()方法判断目标值与数组元素是否相等
2 如果相等返回一个数组元素的索引值

实现代码如下:

ListIntf接口

public interface ListIntf {   public int size();  //获取链表长度public void clear();  //清空链表public boolean isEmpty(); //判断是否为空表public Object get(int i); //获取i位置的元素public int indexOf(Object obj); //获取元素的索引位置public Object getPre(Object obj);// 获取前驱元素public Object getNext(Object obj);//获取后驱元素public void insertElementAt(Object obj,int i);//插入元素public Object remove(int i);//移除元素public Object remove(Object obj);//移除元素}

继承ListIntf接口的Sqlist程序:

public class Sqlist implements ListIntf{   	final int maxlen=100;	int len=80;	int num[]=new int[100];		public Sqlist() {      //构造方法		for(int i=0;i
len) { System.out.println("插入位置不对"); }else { for(int j=len;i
len) { System.out.println("插入位置不对"); }else { for(int j=i-1;j

运行结果:

数值是16的索引值是16--------------我是分割线-----------索引16位置前驱元素是15--------------我是分割线-----------索引16位置后驱元素是17--------------我是分割线-----------索引16位置的元素是17--------------我是分割线-----------在80索引处插入81,链表为123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081--------------我是分割线-----------移除索引1的值,链表为23456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081--------------我是分割线-----------移除数值是81的值,链表为234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980--------------我是分割线-----------清空表:0000000000000000000000000000000000000000000000000000000000000000000000000000000

转载地址:http://uhwcz.baihongyu.com/

你可能感兴趣的文章
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>