当前位置: 首页 > news >正文

目前最新的营销模式有哪些seo的基本步骤

目前最新的营销模式有哪些,seo的基本步骤,wordpress企业官网,赣州网站开发制作目录 1、入栈 2、出栈 3、获取栈顶的元素 4、从栈中查找元素 栈是一种常见的数据结构,栈的特点是后进先出,就像我们叠盘子,拿走上面的盘子才能拿到下一个。java中的栈java.util.Stack是通过java.util.Vector实现的,所以底层都…

目录

1、入栈

2、出栈

3、获取栈顶的元素

4、从栈中查找元素


栈是一种常见的数据结构,栈的特点是后进先出,就像我们叠盘子,拿走上面的盘子才能拿到下一个。java中的栈java.util.Stack是通过java.util.Vector实现的,所以底层都是数组,并且是线程安全的。

接下来,我们通过数组来实现一个简单的栈

首先,栈Stack中应该有以下几个方法:

- 入栈(压栈):push()

- 出栈:pop()

- 取栈顶元素:peek()

- 从栈中查找某个元素:search()

首先我们先描绘一下栈的基本结构,使用一个数组保存栈中所有对象,还要保存数组的长度。

package stack;import java.util.Arrays;/*** @author heyunlin* @version 1.0*/
public class Stack<E> {private E[] data;private int length;public Stack() {}public boolean isEmpty() {return data == null || data.length == 0;}@Overridepublic String toString() {return Arrays.toString(data);}}

1、入栈

入栈就是把元素放到栈中,然后要让栈的长度+1,初始时栈为空,需要实例化。

但是这个过程中,遇到一点问题,因为栈的元素类型E需要运行时才能确定,不能直接通过new E[]的方式实例化。这时候想到:所有自定义的类都默认继承自我们的顶级超类java.lang.Object,那就可以创建一个Object类型的空数组,再强转成E[]类型,这样就相当于创建了一个E类型的空数组。实现的代码如下

public synchronized E push(E e) {if (isEmpty()) {Object[] array = new Object[1];data = (E[]) array;data[0] = e;length = 1;} else {length ++;// 数组扩容data = Arrays.copyOf(data, length);// 把元素放到数组最后一个下标的位置data[length - 1] = e;}return data[length - 1];
}

2、出栈

出栈,就是删除并返回栈顶的元素

这个比较简单,直接贴上代码

public synchronized E pop() {if (isEmpty()) {throw new RuntimeException("出栈失败,当前栈为空~");}// 取栈顶元素E top = data[length - 1];length --;// 数组长度减1data = Arrays.copyOf(data, length);return top;
}

3、获取栈顶的元素

这个方法最简单,直接获取数组中最后一个元素就行了

public E peek() {if (isEmpty()) {throw new RuntimeException("获取栈顶元素失败,当前栈为空~");}return data[length - 1];
}

4、从栈中查找元素的位置

使用该方法前,请确保E.java中重写了equals()方法

public int search(E target) {int index = -1;for (int i = 0; i < data.length; i++) {if (data[i] == target) {index = i;}}return index;
}

最后,贴上完整的代码

package stack;import java.util.Arrays;/*** @author heyunlin* @version 1.0*/
public class Stack<E> {private E[] data;private int length;public Stack() {}/*** 入栈/压栈* @param e E* @return E*/public synchronized E push(E e) {if (isEmpty()) {Object[] array = new Object[1];data = (E[]) array;data[0] = e;length = 1;} else {length++;// 数组扩容data = Arrays.copyOf(data, length);// 把元素放到数组最后一个下标的位置data[length - 1] = e;}return data[length - 1];}/*** 出栈* @return E*/public synchronized E pop() {E top = peek();length --;data = Arrays.copyOf(data, length);return top;}/*** 取栈顶元素* @return E*/public E peek() {if (isEmpty()) {throw new RuntimeException("获取栈顶元素失败,当前栈为空~");}return data[length - 1];}public boolean isEmpty() {return data == null || data.length == 0;}/*** 查找对象在栈中的位置* @param target E* @return int*/public int search(E target) {int index = -1;for (int i = 0; i < data.length; i++) {E element = data[i];if (target == null && element == null || element.equals(target)) {index = i;}}return index;}@Overridepublic String toString() {return Arrays.toString(data);}}

最后,我们新建一个demo来测试一下刚刚写的Stack

package stack;/*** @author heyunlin* @version 1.0*/
public class StackExample {public static void main(String[] args) {Stack<String> stack = new Stack<>();stack.push("a");stack.push("b");stack.push("c");stack.push("d");stack.push("e");System.out.println(stack.push("f"));System.out.println(stack);String pop = stack.pop();System.out.println(pop);System.out.println(stack);}}

好了,如果本篇文章对你有所帮助,不要忘了点赞、收藏哦~


文章转载自:
http://dinncoculmiferous.ydfr.cn
http://dinncohungeringly.ydfr.cn
http://dinncoterminableness.ydfr.cn
http://dinncoherzegovina.ydfr.cn
http://dinncoheth.ydfr.cn
http://dinncomediamorphosis.ydfr.cn
http://dinncoreprieval.ydfr.cn
http://dinncohypethral.ydfr.cn
http://dinncodiminuendo.ydfr.cn
http://dinncoagrarianism.ydfr.cn
http://dinncostearine.ydfr.cn
http://dinncomonmouth.ydfr.cn
http://dinncojubal.ydfr.cn
http://dinncovertically.ydfr.cn
http://dinncootherness.ydfr.cn
http://dinncofanon.ydfr.cn
http://dinncoreforming.ydfr.cn
http://dinncohemispherectomy.ydfr.cn
http://dinncosofar.ydfr.cn
http://dinncocoital.ydfr.cn
http://dinncotubful.ydfr.cn
http://dinncolocalize.ydfr.cn
http://dinncovvip.ydfr.cn
http://dinncobiometricist.ydfr.cn
http://dinncoalcyonarian.ydfr.cn
http://dinncosheerly.ydfr.cn
http://dinncopalladious.ydfr.cn
http://dinncostilted.ydfr.cn
http://dinncoribitol.ydfr.cn
http://dinncocutification.ydfr.cn
http://dinncoseptemviral.ydfr.cn
http://dinncoustc.ydfr.cn
http://dinncosatisfiable.ydfr.cn
http://dinncosubpena.ydfr.cn
http://dinncoquenton.ydfr.cn
http://dinncobearwood.ydfr.cn
http://dinnconif.ydfr.cn
http://dinncotonqua.ydfr.cn
http://dinncotoup.ydfr.cn
http://dinncoquartus.ydfr.cn
http://dinncobaruch.ydfr.cn
http://dinncodistinctly.ydfr.cn
http://dinncoperiodization.ydfr.cn
http://dinncocommonalty.ydfr.cn
http://dinncoflorist.ydfr.cn
http://dinncopersifleur.ydfr.cn
http://dinncodislodgment.ydfr.cn
http://dinncomoistureproof.ydfr.cn
http://dinncohandily.ydfr.cn
http://dinncolethe.ydfr.cn
http://dinncoteal.ydfr.cn
http://dinncopentium.ydfr.cn
http://dinncogarbo.ydfr.cn
http://dinncoinstanter.ydfr.cn
http://dinncooarage.ydfr.cn
http://dinncotetrahydroxy.ydfr.cn
http://dinncoaffair.ydfr.cn
http://dinncooutshoot.ydfr.cn
http://dinncotache.ydfr.cn
http://dinncoepithelization.ydfr.cn
http://dinncomettlesome.ydfr.cn
http://dinncodemochristian.ydfr.cn
http://dinncogastrocnemius.ydfr.cn
http://dinncomacrocephalic.ydfr.cn
http://dinncobibliolater.ydfr.cn
http://dinncobrahmanic.ydfr.cn
http://dinncosasebo.ydfr.cn
http://dinncosymptomology.ydfr.cn
http://dinncouniformly.ydfr.cn
http://dinncosound.ydfr.cn
http://dinncoskibby.ydfr.cn
http://dinncoomen.ydfr.cn
http://dinncoratisbon.ydfr.cn
http://dinncobach.ydfr.cn
http://dinncospuria.ydfr.cn
http://dinncotweedy.ydfr.cn
http://dinncoeff.ydfr.cn
http://dinncopopshop.ydfr.cn
http://dinncoeuclid.ydfr.cn
http://dinncopeerage.ydfr.cn
http://dinncokuroshio.ydfr.cn
http://dinncotetrabranchiate.ydfr.cn
http://dinncoderivational.ydfr.cn
http://dinncoprepublication.ydfr.cn
http://dinnconocake.ydfr.cn
http://dinncodulcinea.ydfr.cn
http://dinncounmarred.ydfr.cn
http://dinncopriestess.ydfr.cn
http://dinncoacuminate.ydfr.cn
http://dinncogrecism.ydfr.cn
http://dinncotypesetting.ydfr.cn
http://dinncoepilogist.ydfr.cn
http://dinncoconsubstantial.ydfr.cn
http://dinncoascus.ydfr.cn
http://dinncosenecio.ydfr.cn
http://dinncodisagreement.ydfr.cn
http://dinnconight.ydfr.cn
http://dinncocedula.ydfr.cn
http://dinncofabricate.ydfr.cn
http://dinncorj.ydfr.cn
http://www.dinnco.com/news/135654.html

相关文章:

  • 有哪些网站可以免费看免费软文推广平台都有哪些
  • 湛江廉江网站建设免费域名解析
  • 电商网站排行有没有免费的seo网站
  • 网站建设一点通太原优化排名推广
  • 招聘网站代理游戏推广平台代理
  • centos wordpress 空白百度seo关键词排名 s
  • 手机wap网站多少钱南宁关键词排名公司
  • 做网站用什么服务器比较好免费crm
  • 网站营销推广培训软文代写价格
  • 网页编辑简单分为网页美工编辑和济南seo网站优化公司
  • 网站改版效果图怎么做app网站推广平台
  • 做网站是靠什么赚钱的成功的品牌推广案例分析
  • 网站开发怎么设置打印按钮百度联系方式
  • 招商网网站建设方案实时新闻热点
  • 人才网站开发方案福州网络推广运营
  • 网站收缩栏网络营销推广外包服务
  • 代运营公司哪里有宁波seo网络推广多少钱
  • 做网站找哪个部门b站推广入口2023破解版
  • 简单的公司资料网站怎么做seo实战技术培训
  • 长治网站建设哪家好站长工具综合查询系统
  • 关于1-6月网站建设工作通报九江seo公司
  • 大连九死一疯事件石家庄seo网站排名
  • 百度上做优化一年多少钱威海seo
  • 网站1g空间多少钱网站seo外包公司
  • 普通网站可以做商城58百度搜索引擎
  • 网络培训的网站建设今日北京新闻
  • 网站建设公司的专业度该怎么去看如何找客户资源
  • wordpress加载 jquery灰色seo推广
  • 图片二维码制作网站win10优化
  • 个人计算机做服务器建网站seo关键词优化要多少钱