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

静态网站怎么更新自己怎么制作logo图标

静态网站怎么更新,自己怎么制作logo图标,临沂手机网站开发制作公司,免费推广店铺的网站1. 栈(Stack) 1.1 概念 栈#xff1a;一种特殊的线性表#xff0c;其只允许在固定的一端进行插入和删除元素操作。进行数据插入和删除操作的一端称为栈 顶#xff0c;另一端称为栈底。栈中的数据元素遵守后进先出LIFO#xff08;Last In First Out#xff09;的原则。 … 1. 栈(Stack) 1.1 概念 栈一种特殊的线性表其只允许在固定的一端进行插入和删除元素操作。进行数据插入和删除操作的一端称为栈 顶另一端称为栈底。栈中的数据元素遵守后进先出LIFOLast In First Out的原则。 压栈栈的插入操作叫做进栈/压栈/入栈入数据在栈顶。 出栈栈的删除操作叫做出栈。出数据在栈顶。 1.2 栈的使用 从上图中可以看到Stack继承了VectorVector和ArrayList类似都是动态的顺序表不同的Vector是线程安全Vector类是线程安全的动态数组但是性能较差 , 现在已经不是很常用了 , 可以说已经过时了。 常用方法 方法功能Stack()构造一个空的栈E push(E e)将e入栈并返回eE pop()将栈顶元素出栈并返回E peek()获取栈顶元素int size()获取栈中有效元素个数boolean empty()检测栈是否为空 public static void main(String[] args) { StackInteger s new Stack(); s.push(1); s.push(2); s.push(3); s.push(4); System.out.println(s.size()); // 获取栈中有效元素个数--- 4 System.out.println(s.peek()); // 获取栈顶元素--- 4 s.pop(); // 4出栈栈中剩余1 2 3栈顶元素为3 System.out.println(s.pop()); // 3出栈栈中剩余1 2 栈顶元素为3 if(s.empty()){ System.out.println(栈空); }else{ System.out.println(s.size());} } 1.3 栈的模拟实现 从上图中可以看到Stack继承了VectorVector和ArrayList类似都是动态的顺序表不同的是Vector是线程安 全的。 代码实现 1. 构造方法 class MyStack{private int[] arr;// size 记录栈中元素个数private int size;public MyStack(){// 调用无参构造方法 默认最大容量12this(12);}public MyStack(int MaxSize){this.arr new int[MaxSize];} }2. 入栈(push) // 入栈public int push(int value){if(this.size arr.length){// 栈满 ,需要扩容int[] copyArr;// 复制arr 数组并扩容一倍copyArr Arrays.copyOf(arr,2 * arr.length);arr copyArr;}//将元素添加到size位置this.arr[size] value;// 元素个数加一this.size;// 返回添加元素return value;}3. 出栈(pop) // 出栈public int pop(){if(this.size 0){//没有元素//抛出运行时异常,此处也可以自定义异常throw new RuntimeException(栈中没有元素,不能出栈....);}// 获得栈顶元素int value this.arr[size - 1];// size - 1 之后, 下一次插入时会覆盖原数据,利用覆盖替代删除this.size--;return value;}4.获取栈顶元素(peek) // 获取栈顶元素public int peek(){if(this.size 0){//没有元素//抛出运行时异常,此处也可以自定义异常throw new RuntimeException(栈中没有元素,不能出栈....);}return this.arr[this.size - 1];}5.获取元素个数(getSize) //获取元素个数public int getSize(){return this.size;}6.判断栈是否为空(isEmpty) //判断元素是否为空public boolean isEmpty(){return this.size 0;}完整代码 import java.util.Arrays;public class MyStack{private int[] arr;// size 记录栈中元素个数private int size;public MyStack(){// 调用无参构造方法 默认最大容量12this(12);}public MyStack(int MaxSize){this.arr new int[MaxSize];}// 入栈public int push(int value){if(this.size arr.length){// 栈满 ,需要扩容int[] copyArr;// 复制arr 数组并扩容一倍copyArr Arrays.copyOf(arr,2 * arr.length);arr copyArr;}//将元素添加到size位置this.arr[size] value;// 元素个数加一this.size;// 返回添加元素return value;}// 出栈public int pop(){if(isEmpty()){//没有元素//抛出运行时异常,此处也可以自定义异常throw new RuntimeException(栈中没有元素,不能出栈....);}// 获得栈顶元素int value this.arr[size - 1];// size - 1 之后, 下一次插入时会覆盖原数据,利用覆盖替代删除this.size--;return value;}// 获取栈顶元素public int peek(){if(isEmpty()){//没有元素//抛出运行时异常,此处也可以自定义异常throw new RuntimeException(栈中没有元素,不能出栈....);}return this.arr[this.size - 1];}//获取元素个数public int getSize(){return this.size;}//判断元素是否为空public boolean isEmpty(){return this.size 0;} }1.4 栈的应用场景 1. 改变元素的序列 1. 若进栈序列为 1,2,3,4 进栈过程中可以出栈则下列不可能的一个出栈序列是      A: 1,4,3,2                      B: 2,3,4,1                 C: 3,1,4,2                            D: 3,4,2,1 根据栈先进后出的性质结合题目中进栈的过程中也可以出栈如A选项1进1出,2进3进4进4出3出2出即符合题意同理C选项1进2进3进3出之后不可能直接出1故C选项不可能实现。 2.一个栈的初始状态为空。现将元素1、2、3、4、5、A、B、C、D、E依次入栈然后再依次出栈则元素出栈的顺 序是 。 A: 12345ABCDE          B: EDCBA54321         C: ABCDE12345           D: 54321EDCBA 先进后出依次入栈依次出栈故B选项合理 2. 将递归转化为循环 递归实现逆序打印 public void display(ListNode head){if(head null){return;}//直到链表末尾再归回去if(head.next null){System.out.println(head.val );return;}display(head.next);System.out.println(head.val ); } 使用栈实现逆序打印 public void display(ListNode head){if(head null){return;}StackListNode stack new Stack();ListNode cur head;while(cur! null){stack.push(cur);cur cur.next;}while(!stack.empty()){ListNode ret stack.pop();System.out.println(ret.val );}} 2. 队列(Queue) 2.1 概念 队列只允许在一端进行插入数据操作在另一端进行删除数据操作的特殊线性表队列具有先进先出FIFO(First In First Out) 入队列进行插入操作的一端称为队尾Tail/Rear 出队列进行删除操作的一端称为队头 Head/Front 2.2 队列的使用 在Java中Queue是个接口底层是通过链表实现的。 方法功能boolean offer(E e) 入队列E poll() 出队列peek() 获取队头元素int size() 获取队列中有效元素个数boolean isEmpty()检测队列是否为空 注意Queue是个接口在实例化时必须实例化LinkedList的对象因为LinkedList实现了Queue接口。 public static void main(String[] args) { QueueInteger q new LinkedList(); q.offer(1); q.offer(2); q.offer(3); q.offer(4); q.offer(5); // 从队尾入队列 System.out.println(q.size()); System.out.println(q.peek()); // 获取队头元素 q.poll(); System.out.println(q.poll()); // 从队头出队列并将删除的元素返回 if(q.isEmpty()){ System.out.println(队列空); }else{ System.out.println(q.size()); } }2.3 队列模拟实现 队列中既然可以存储元素那底层肯定要有能够保存元素的空间通过前面线性表的学习了解到常见的空间类型有两种:顺序结构和链式结构 。 public class Queue {// 双向链表节点public static class ListNode{ListNode next;ListNode prev;int value;ListNode(int value){this.value value;}}ListNode first; // 队头ListNode last; // 队尾int size 0;// 入队列---向双向链表位置插入新节点public void offer(int e){ListNode newNode new ListNode(e);if(first null){first newNode; // last newNode;}else{last.next newNode;newNode.prev last; // last newNode;}last newNode;size;}// 出队列---将双向链表第一个节点删除掉public int poll(){ // 1. 队列为空 // 2. 队列中只有一个元素----链表中只有一个节点---直接删除 // 3. 队列中有多个元素---链表中有多个节点----将第一个节点删除int value 0;if(first null){return null;}else if(first last){last null;first null;}else{value first.value;first first.next;first.prev.next null;first.prev null;}--size;return value;}// 获取队头元素---获取链public int peek(){if(first null){return null;}return first.value;}public int size() {return size;}public boolean isEmpty(){return first null;} } 2.4 循环队列 实际中我们有时还会使用一种队列叫循环队列。如操作系统课程讲解生产者消费者模型时可以就会使用循环队列。环形队列通常使用数组实现。 数组下标循环的小技巧  1. 下标最后再往后(offset 小于 array.length): index (index offset) % array.length 2. 下标最前再往前(offset 小于 array.length): index (index array.length - offset)%array.length 如何区分空与满 1. 通过添加 size 属性记录 2. 保留一个位置 3. 使用标记 public class CircularQueue {private int front;private int rear;private int[] circle;public CircularQueue(int k) {//浪费掉一个存储空间circle new int[k1];}//入队列public boolean enQueue(int value) {if (isFull()) {return false;}circle[rear] value;//因为是循环队列不能写要以取模的方式rear (rear 1) % circle.length;return true;}//出队列public boolean deQueue() {if (isEmpty()) {return false;}front (front 1) % circle.length;return true;}//返回队头元素public int Front() {if (isEmpty()) {return -1;}return circle[front];}//返回队尾元素public int Rear() {if (isEmpty()) {return -1;}return circle[(rear - 1 circle.length) % circle.length];}public boolean isEmpty() {return rear front;}public boolean isFull() {return ((rear 1) % circle.length) front;}}3.  双端队列 (Deque) 双端队列deque是指允许两端都可以进行入队和出队操作的队列deque 是 “double ended queue” 的简称。那就说明元素可以从队头出队和入队也可以从队尾出队和入队。 Deque是一个接口使用时必须创建LinkedList的对象。 在实际工程中使用Deque接口是比较多的栈和队列均可以使用该接口。 DequeInteger stack new ArrayDeque();//双端队列的线性实现 DequeInteger queue new LinkedList();//双端队列的链式实现 4. 栈和队列的互相实现 用栈实现队列 class MyQueue {public StackInteger stack1;public StackInteger stack2;public MyQueue() {stack1 new Stack();stack2 new Stack();}public void push(int x) {stack1.push(x);}public int pop() {if (stack2.isEmpty()) { in2out();}return stack2.pop();}public int peek() {if (stack2.isEmpty()){ in2out();}return stack2.peek();}public boolean empty() {return stack1.isEmpty() stack2.isEmpty();}private void in2out() {while (!stack1.isEmpty()) {stack2.push(stack1.pop());}} } 用队列实现栈 class MyStack {QueueInteger queue1;QueueInteger queue2;public MyStack() {queue1 new LinkedListInteger();queue2 new LinkedListInteger();}public void push(int x) {queue2.offer(x);while (!queue1.isEmpty()) {queue2.offer(queue1.poll());}QueueInteger temp queue1;queue1 queue2;queue2 temp;}public int pop() {return queue1.poll();}public int top() {return queue1.peek();}public boolean empty() {return queue1.isEmpty();} }
http://www.dnsts.com.cn/news/8614.html

相关文章:

  • 甘肃网站建设方案服务至上无锡新吴区住房和建设交通局网站
  • 阿里云重新备案注销主体还是注销网站php网站做语言包
  • 做阿里巴巴网站图片尺寸百度云盘做网站
  • 问答社区网站建设怎样可以有自己的网站
  • 福州网站制作维护公司网页制作模板图片
  • 徐州市城乡建设局网站6外贸网站源码多语言
  • 霸屏网站开发十大酒店管理系统
  • 深圳企业网站建设价格wordpress setup_theme
  • 怎么样做一家卖东西的网站会展策划与管理
  • 沈阳网站设计福州百度推广排名
  • 长宁免费网站制作wordpress搜索筛选
  • 网站的目标定位有哪些不封号的电销系统
  • 拓普网站建设百度seo排名在线点击器
  • 平台类网站制作公司wordpress 微博同步
  • 做平面有什么好的网站北京市文化局政务网站建设项目
  • 免费网站建设模版云盘网站模版如何使用
  • 如何申请网站怎么在百度免费推广
  • 南京做网站团队安徽六安怎么读
  • 做网站推广前途网站开发(源代码)
  • 嘉兴高端网站公司公众号运营方案
  • 企业网站的需求是什么wordpress仿微博
  • 百度SEO是谁做的网站绍兴网站设计公司
  • 西安网站建设第一品牌企业网站建设的步骤过程
  • 信息类网站南京小程序定制开发
  • 网站站内推广怎么做群晖wordpress打开慢
  • 挂甲寺网站建设网站开发兼容ie
  • 旅游网站建设经济评价做网站放哪个科目
  • 厚街仿做网站新浪微指数
  • 石龙仿做网站聊城开发网站建设
  • 网站建设流程行情怎么查询商标名称是否注册