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

服务器可以放几个网站新余做网站的

服务器可以放几个网站,新余做网站的,wordpress英文改中文,怀化百度整站优化服务文章目录 一、什么是栈#xff1f;1.1 栈的模拟实现1.2 关于栈的例题 二、什么是队列#xff1f;2.2 队列的模拟实现2.2 关于队列的例题 总结 提示#xff1a;关于栈和队列的实现其实很简单#xff0c;基本上是对之前的顺序表和链表的一种应用#xff0c;代码部分也不难。… 文章目录 一、什么是栈1.1 栈的模拟实现1.2 关于栈的例题 二、什么是队列2.2 队列的模拟实现2.2 关于队列的例题 总结 提示关于栈和队列的实现其实很简单基本上是对之前的顺序表和链表的一种应用代码部分也不难。主要的是对栈和队列的实际运用。 一、什么是栈 可以理解为一个竖过来的数组、顺序表同时这个数组只能将末尾的元素先推出来再推出来前面的元素也就是我们所说的先进后出、后进先出。 栈的实例化 StackE stack new Stack();1.1 栈的模拟实现 自定义的接口规范自定义的类,便于模拟实现 public interface IStack {//放入元素int push(int a);//推出栈顶元素int pop();//查看栈顶元素int peek();//栈是否为空boolean isEmpty(int[] array);//栈中的元素个数int size();//栈中寻找某个元素距离栈顶的距离int search(int a); } push(int a) — 将元素放入栈中 public int push(int a) {isFull(array);array[useSide] a;return a;}peek() — 查看栈顶元素 public int peek() {try {if(isEmpty(array)){throw new EmptyException(空数组读取异常);}}catch (EmptyException e){e.printStackTrace();}return array[useSide - 1];}pop() — 出栈顶元素 public int pop() {int top peek();useSide--;return top;}isEmpty(int[] array) — 判断栈是否为空 public boolean isEmpty(int[] array) {return array.length useSide;}size() — 得到栈中的元素个数 public int size() {return useSide;}search(int a) — 得到栈中某个元素距离栈顶的距离栈顶元素位置按1来计算 public int search(int a) {int cur useSide - 1;int len 1;while (0 cur){if(a array[cur]){return len;}else {cur--;len;}}return -1;}代码整合 public class MyStack implements IStack{private int[] array;public MyStack() {this.array new int[10];}private int useSide;private void isFull(int[] check){if(isEmpty(check)){array Arrays.copyOf(check,2*check.length);}}Overridepublic int push(int a) {isFull(array);array[useSide] a;return a;}Overridepublic int pop() {int top peek();useSide--;return top;}Overridepublic int peek() {try {if(isEmpty(array)){throw new EmptyException(空数组读取异常);}}catch (EmptyException e){e.printStackTrace();}return array[useSide - 1];}Overridepublic boolean isEmpty(int[] array) {return array.length useSide;}Overridepublic int size() {return useSide;}Overridepublic int search(int a) {int cur useSide - 1;int len 1;while (0 cur){if(a array[cur]){return len;}else {cur--;len;}}return -1;} }1.2 关于栈的例题 例题1 有效括号 class Solution {public boolean isValid(String s) {StackCharacter stack new Stack();if(s null){return false;}for(int i 0; i s.length(); i){char cur s.charAt(i);if(cur ( || cur { || cur [){stack.push(cur);}else if(cur ) || cur } || cur ]){if(stack.isEmpty()){return false;}if(cur )stack.peek() ( || cur }stack.peek() { || cur ]stack.peek() [){stack.pop();}else{return false;}}else{return false;}}if(stack.isEmpty()){return true;}return false;} }例题2 逆波兰表达式 public int evalRPN(String[] tokens) {StackString stack new Stack();for(int i 0; i tokens.length; i){if(tokens[i].equals() || tokens[i].equals(-) || tokens[i].equals(*) || tokens[i].equals(/)){int m Integer.parseInt(stack.pop());int n Integer.parseInt(stack.pop());if(tokens[i].equals()){stack.push(String.valueOf(mn));}else if(tokens[i].equals(-)){stack.push(String.valueOf(n-m));}else if(tokens[i].equals(*)){stack.push(String.valueOf(m*n));}else{stack.push(String.valueOf(n/m));}}else{stack.push(tokens[i]);}}return Integer.parseInt(stack.pop());}例题3 最小栈 public StackInteger stack;public StackInteger minStack;public MinStack() {stack new Stack();minStack new Stack();}public void push(int val) {stack.push(val);if(minStack.empty()){minStack.push(val);}else{int m minStack.peek();if(m val){minStack.push(val);}}}public void pop() {if(stack.empty()){return;}int m stack.pop();if(m minStack.peek()){minStack.pop();}}public int top() {if(stack.empty()){return -1;}return stack.peek();}public int getMin() {if(minStack.empty()){return -1;}return minStack.peek();}例题4 栈的压入、弹出序列 public boolean IsPopOrder (int[] pushV, int[] popV) {// write code hereStackInteger stack new Stack();int j 0;for(int i 0; i pushV.length;i){stack.push(pushV[i]);while(!stack.isEmpty() stack.peek() popV[j] j popV.length){stack.pop();j;}}return stack.isEmpty();}二、什么是队列 可以理解为一个双向链表(一个一个节点在排队)同时这个链表只能将队头的元素先推出来再推出来后面的元素也就是我们所说的先进先出、后进后出。 队列的实例化 DequeE stack new ArrayDeque();//双端队列的线性实现 DequeE queue new LinkedList();//双端队列的链式实现2.2 队列的模拟实现 自定义的接口规范自定义的类,便于模拟实现 public interface IQueue {//int offer(int a);int poll();int peek();boolean isEmpty(); }isEmpty() — 判断是否为空队列 Overridepublic boolean isEmpty() {return useSide 0;}offer(int a) — 从队尾放入元素 public int offer(int a) {ListNode listNode new ListNode(a);listNode.val a;if(isEmpty()){head listNode;last listNode;}else {last.next listNode;listNode.pre last;last listNode;}useSide;return a;}peek() — 查看队头元素 public int peek() {try {if(head null){throw new EmptyException(空指针异常访问);}}catch (EmptyException e){e.printStackTrace();}return head.val;}poll() — 推出队头的元素 public int poll() {int fisrt peek();head head.next;useSide --;return fisrt;}代码整合 public class MyQueue implements IQueue{static class ListNode{int val;ListNode pre;ListNode next;public ListNode(int val) {this.val val;}}private ListNode head;private ListNode last;private int useSide;Overridepublic int offer(int a) {ListNode listNode new ListNode(a);listNode.val a;if(isEmpty()){head listNode;last listNode;}else {last.next listNode;listNode.pre last;last listNode;}useSide;return a;}Overridepublic int poll() {int fisrt peek();head head.next;useSide --;return fisrt;}Overridepublic int peek() {try {if(head null){throw new EmptyException(空指针异常访问);}}catch (EmptyException e){e.printStackTrace();}return head.val;}Overridepublic boolean isEmpty() {return useSide 0;}} 2.2 关于队列的例题 例题1 设计循环队列 class MyCircularQueue {public int[] array;int front;int rear;public MyCircularQueue(int k) {array new int[k1];}// 向循环队列插入一个元素。如果成功插入则返回真。public boolean enQueue(int value) {if(isFull()){return false;}array[rear] value;rear (rear1) % array.length;return true;}//从循环队列中删除一个元素。如果成功删除则返回真。public boolean deQueue() {if(isEmpty()){return false;}front (front1) % array.length;return true;}//从队首获取元素。如果队列为空返回 -1 。public int Front() {if(isEmpty()){return -1;}return array[front];}//获取队尾元素。如果队列为空返回 -1 。public int Rear() {if(isEmpty()){return -1;}if(rear 0){return array[array.length - 1];}return array[rear-1];}//检查循环队列是否为空。public boolean isEmpty() {return rear front;}//检查循环队列是否已满。public boolean isFull() {return (rear1) % array.length front;} }例题2 用队列实现栈 class MyStack {public QueueInteger queue1;public QueueInteger queue2;int size;public MyStack() {queue1 new LinkedList();queue2 new LinkedList();}public void push(int x) {if(queue1.isEmpty() queue2.isEmpty()){queue1.offer(x);size;}else if(!queue1.isEmpty()){queue1.offer(x);size;}else if(!queue2.isEmpty()){queue2.offer(x);size;}}public int pop() {if(queue1.isEmpty() queue2.isEmpty()){return -1;}if(queue1.isEmpty() !queue2.isEmpty()){int cur size - 1;while(cur ! 0){queue1.offer(queue2.poll());cur--;}size--;return queue2.poll();}else if(!queue1.isEmpty() queue2.isEmpty()){int cur size - 1;while(cur ! 0){queue2.offer(queue1.poll());cur--;}size--;return queue1.poll();}return -1;}public int top() {if(queue1.isEmpty() queue2.isEmpty()){return -1;}if(queue1.isEmpty() !queue2.isEmpty()){int cur size - 1;while(cur ! 0){queue1.offer(queue2.poll());cur--;}int m queue2.peek();queue1.offer(queue2.poll());return m;}else if(!queue1.isEmpty() queue2.isEmpty()){int cur size - 1;while(cur ! 0){queue2.offer(queue1.poll());cur--;}int m queue1.peek();queue2.offer(queue1.poll());return m;}return -1;}public boolean empty() {return size 0;}}例题3 用栈实现队列 StackInteger stack1;StackInteger stack2;int size 0;public MyQueue() {stack1 new Stack();stack2 new Stack();}//将元素 x 推到队列的末尾public void push(int x) {stack1.push(x);size;}//从队列的开头移除并返回元素public int pop() {if(empty()){return -1;}if(!stack2.isEmpty()){size--;return stack2.pop();}else if(stack2.isEmpty() !stack1.isEmpty()){while(!stack1.isEmpty()){stack2.push(stack1.pop());}size--;return stack2.pop();}return -1;}//返回队列开头的元素public int peek() {if(empty()){return -1;}if(!stack2.isEmpty()){return stack2.peek();}else if(stack2.isEmpty() !stack1.isEmpty()){while(!stack1.isEmpty()){stack2.push(stack1.pop());}return stack2.peek();}return -1;}//如果队列为空返回 true 否则返回 falsepublic boolean empty() {return size 0;}总结 本篇文章介绍了有关数据结构中的栈和队列的相关内容以及它们的简单实现和简单使用如果有什么不正确的或者不严谨的地方还望指正谢谢大家
文章转载自:
http://www.morning.bzfld.cn.gov.cn.bzfld.cn
http://www.morning.kxltf.cn.gov.cn.kxltf.cn
http://www.morning.rrwgh.cn.gov.cn.rrwgh.cn
http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn
http://www.morning.jrslj.cn.gov.cn.jrslj.cn
http://www.morning.yxbrn.cn.gov.cn.yxbrn.cn
http://www.morning.yaqi6.com.gov.cn.yaqi6.com
http://www.morning.cdrzw.cn.gov.cn.cdrzw.cn
http://www.morning.sbyhj.cn.gov.cn.sbyhj.cn
http://www.morning.lgsqy.cn.gov.cn.lgsqy.cn
http://www.morning.xldpm.cn.gov.cn.xldpm.cn
http://www.morning.djlxz.cn.gov.cn.djlxz.cn
http://www.morning.frtb.cn.gov.cn.frtb.cn
http://www.morning.cywf.cn.gov.cn.cywf.cn
http://www.morning.jbctp.cn.gov.cn.jbctp.cn
http://www.morning.qgbfx.cn.gov.cn.qgbfx.cn
http://www.morning.cnqff.cn.gov.cn.cnqff.cn
http://www.morning.jlschmy.com.gov.cn.jlschmy.com
http://www.morning.hengqilan.cn.gov.cn.hengqilan.cn
http://www.morning.ybnzn.cn.gov.cn.ybnzn.cn
http://www.morning.fhrt.cn.gov.cn.fhrt.cn
http://www.morning.hryhq.cn.gov.cn.hryhq.cn
http://www.morning.lqlhw.cn.gov.cn.lqlhw.cn
http://www.morning.hjlsll.com.gov.cn.hjlsll.com
http://www.morning.gjtdp.cn.gov.cn.gjtdp.cn
http://www.morning.xbnkm.cn.gov.cn.xbnkm.cn
http://www.morning.bnmrp.cn.gov.cn.bnmrp.cn
http://www.morning.deanzhu.com.gov.cn.deanzhu.com
http://www.morning.mrcpy.cn.gov.cn.mrcpy.cn
http://www.morning.mjzgg.cn.gov.cn.mjzgg.cn
http://www.morning.gwqcr.cn.gov.cn.gwqcr.cn
http://www.morning.wschl.cn.gov.cn.wschl.cn
http://www.morning.bhgnj.cn.gov.cn.bhgnj.cn
http://www.morning.pjxw.cn.gov.cn.pjxw.cn
http://www.morning.wbqt.cn.gov.cn.wbqt.cn
http://www.morning.cybch.cn.gov.cn.cybch.cn
http://www.morning.nxbsq.cn.gov.cn.nxbsq.cn
http://www.morning.wqbzt.cn.gov.cn.wqbzt.cn
http://www.morning.nmrtb.cn.gov.cn.nmrtb.cn
http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn
http://www.morning.nwqyq.cn.gov.cn.nwqyq.cn
http://www.morning.tmcmj.cn.gov.cn.tmcmj.cn
http://www.morning.zrfwz.cn.gov.cn.zrfwz.cn
http://www.morning.tknqr.cn.gov.cn.tknqr.cn
http://www.morning.yswxq.cn.gov.cn.yswxq.cn
http://www.morning.glnfn.cn.gov.cn.glnfn.cn
http://www.morning.xmhpq.cn.gov.cn.xmhpq.cn
http://www.morning.bsplf.cn.gov.cn.bsplf.cn
http://www.morning.lhyhx.cn.gov.cn.lhyhx.cn
http://www.morning.txmkx.cn.gov.cn.txmkx.cn
http://www.morning.bnxfj.cn.gov.cn.bnxfj.cn
http://www.morning.gnjkn.cn.gov.cn.gnjkn.cn
http://www.morning.ygxf.cn.gov.cn.ygxf.cn
http://www.morning.cltrx.cn.gov.cn.cltrx.cn
http://www.morning.qljxm.cn.gov.cn.qljxm.cn
http://www.morning.znmwb.cn.gov.cn.znmwb.cn
http://www.morning.fpqsd.cn.gov.cn.fpqsd.cn
http://www.morning.dbqcw.com.gov.cn.dbqcw.com
http://www.morning.ypcbm.cn.gov.cn.ypcbm.cn
http://www.morning.hryhq.cn.gov.cn.hryhq.cn
http://www.morning.qqzdr.cn.gov.cn.qqzdr.cn
http://www.morning.hwnqg.cn.gov.cn.hwnqg.cn
http://www.morning.ljjmr.cn.gov.cn.ljjmr.cn
http://www.morning.ftntr.cn.gov.cn.ftntr.cn
http://www.morning.wmnpm.cn.gov.cn.wmnpm.cn
http://www.morning.tqpds.cn.gov.cn.tqpds.cn
http://www.morning.tsyny.cn.gov.cn.tsyny.cn
http://www.morning.bztzm.cn.gov.cn.bztzm.cn
http://www.morning.gwmjy.cn.gov.cn.gwmjy.cn
http://www.morning.llthz.cn.gov.cn.llthz.cn
http://www.morning.hwljx.cn.gov.cn.hwljx.cn
http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn
http://www.morning.nlmm.cn.gov.cn.nlmm.cn
http://www.morning.rykmf.cn.gov.cn.rykmf.cn
http://www.morning.gmnmh.cn.gov.cn.gmnmh.cn
http://www.morning.rqlf.cn.gov.cn.rqlf.cn
http://www.morning.cfpq.cn.gov.cn.cfpq.cn
http://www.morning.qwrb.cn.gov.cn.qwrb.cn
http://www.morning.jggr.cn.gov.cn.jggr.cn
http://www.morning.okiner.com.gov.cn.okiner.com
http://www.tj-hxxt.cn/news/245346.html

相关文章:

  • 中级建设消防员证书查询网站信得过的网站开发推广
  • 国外贸易网站淘宝客网站哪个好
  • 新网官方网站登陆网站做ppt模板
  • 网站服务类型是什么意思安徽池州网站制作
  • 搭建个人视频网站初级网站开发的自我推荐
  • 宁波专业品牌网站制作外包wordpress 后台慢
  • 北京建设规划许可证网站网站开发 荣誉资质
  • 做网站微信群电子商城网站制作数据库
  • 广州专业网站制作设计做网站找个人还是公司
  • wordpress多站点使用期限插件备案ip 查询网站查询网站
  • 国外在线网站建设平台衣服定制
  • 管理学习网站中国建设工程协会网站电话
  • wordpress 上传网站咸阳seo
  • html怎么发布网页宁波企业网站seo
  • 龙岗义乌网站制作php做网站python做什么
  • 如何添加网站合肥建站平台
  • 惠东网站开发wordpress主题免刷新
  • 网站建设网站营销网站托管一体化wordpress社区代码
  • 微网站开发平台免费wordpress 表单管理
  • 云主机和云电脑的区别昆明网站关键字优化
  • 济南seo整站优化招商电话房地产网站建设策划书
  • 网站设计中常见的错误企业网站策划书制作
  • 官方网站建设怎么样黄河道网站建设
  • 在线做ppt的网站有哪些问题代理网站备案收钱
  • 潍坊网站建设多少钱项目从立项到结束的流程图
  • 北京官方网站网云梦网络做网站
  • 做排名的网站哪个好云虚拟主机怎么做2个网站
  • 做游戏的网站工程项目全过程管理流程
  • 寮步建设网站一键创建网站
  • 上传了网站标志怎么弄手机在线logo生成器