什么是ATOM处理器.有什么特点
什么是ATOM处理器.有什么特点.. 例如功耗和工艺和核心和频率上
更新时间:2022-02-12 10:02
最满意答案
//单链表类 package dataStructure.linearList; import dataStructure.linearList.Node; //导入单链表结点类 import java.util.Iterator; //导入迭代器接口 public class SinglyLinkedListextends AbstractList implements LList //单链表类,实现 线性表接口 { protected Node head; //头指针,指向单链表第1个结点 public SinglyLinkedList() //构造空单链表 { this.head = null; } public SinglyLinkedList(Node head) //构造指定头指针的单链表 { this.head = head; } public boolean isEmpty() //判断单链表是否为空,O(1) { return this.head==null; } public int length() //返回单链表长度 { //单链表遍历算法,O(n) int i=0; Node p=this.head; while (p!=null) { i++; p = p.next; } return i; } public E get(int index) //返回序号为index的对象,index初值为0 { //若单链表空或序号错误返回null,O(n) if (this.head!=null && index>=0) { int j=0; Node p=this.head; while (p!=null && j =0 && element!=null) { int j=0; Node p=this.head; while (p!=null && j (element, this.head); else //单链表不空且index>=1 { int j=0; Node p=this.head; while (p.next!=null && j (element, p.next);//中间/尾插入 } return true; } public boolean add(E element) //在单链表最后添加对象,重载,O(n) { return add(Integer.MAX_VALUE, element); } public E remove(int index) //移去序号为index的对象,O(n) { //若操作成功返回被移去对象,否则返回null E old = null; if (this.head!=null && index>=0) if (index==0) //头删除 { old = (E)this.head.data; this.head = this.head.next; } else //中间/尾删除 { int j=0; Node p=this.head; while (p.next!=null && j p = this.head; while (p!=null) { str += p.data.toString(); p = p.next; if (p!=null) str += ", "; } return str+")"; } //以上实现LList接口,第2章 //以下2.4 迭代器内容 public Iterator iterator() //返回一个迭代器对象 { return new Itr(); } private class Itr implements Iterator //私有 内部类,实现迭代器接口 { private Node cursor = head; public boolean hasNext() //若有后继元素,返回true { return cursor!=null && cursor.next!=null; } public E next() //返回后继元素 { if (cursor != null && cursor.next!=null) { E element = cursor.next.data; cursor = cursor.next; return element; } return null; } public void remove() //不支持该操作 { throw new UnsupportedOperationException(); } }//内部类Itr结束 //以下第8章 8.2.1 顺序查找,散列表中用 public Node search(E element, Node start) //从单链表结点start开始顺序查找指定对象 { //若查找成功返回结点,否则返回null if (this.head==null || element==null) return null; Node p=start; while (p!=null && !element.equals(p.data)) { System.out.print(p.data+"? "); p = p.next; } return p; } public Node search(E element) //顺序查找指定对象 { return search(element, head); } /* public boolean contain(E element) //以查找结果判断单链表是否包含指定对象 { //若包含返回true,否则返回false return this.search(element)!=null; } */ public boolean remove(E element) //移去首次出现的指定对象,O(n) { //若操作成功返回true if (this.head==null || element==null) return false; if (element.equals(this.head.data)) { this.head = this.head.next; //头删除 return true; } Node front=this.head, p=front.next; //中间/尾删除 while (p!=null && !element.equals(p.data)) { front = p; p=p.next; } if (p!=null) { front.next = p.next; return true; } return false; } //以下是第2章习题 public SinglyLinkedList(E[] element) //由指定数组中的多个对象构造单链表 { this.head = null; if (element!=null && element.length>0) { this.head = new Node(element[0]); Node rear=this.head; int i=1; while (i p=this.head; while (p.next!=null) p = p.next; p.next = list.head; } } public SinglyLinkedList(SinglyLinkedList list) //以单链表list构造新的单链表 { //复制单链表 this.head = null; if (list!=null && list.head!=null) { this.head = new Node(list.head.data); Node p = list.head.next; Node rear = this.head; while (p!=null) { rear.next = new Node (p.data); rear = rear.next; p = p.next; } } } //递归方法 // public SinglyLinkedList(SinglyLinkedList list) //以单链表list构造新的单链表 public void copy(SinglyLinkedList list) //复制单链表 { this.head = copy(list.head); } private Node copy(Node p) //复制单链表,递归方法 { Node q=null; if (p!=null) { q = new Node(p.data); q.next = copy(p.next); } return q; } /*//递归方法 public String toString() { return "("+ this.toString(this.head) +")"; } public String toString(Node p) //递归方法 { if (p!=null) return p.data.toString() + ", " + this.toString(p.next); //递归调用 return ""; } public SinglyLinkedList(E[] element) //由指定数组中的多个对象构造单链表 { this.head = null; if (element!=null) this.head = create(element,0); } private Node create(E[] element, int i) //由指定数组构造单链表 { //递归方法 Node p=null; if (i p, Node q) //比较两条单链表是否相等,递归方法 { if (p==null && q==null) return true; if (p!=null && q!=null) return p.data.equals(q.data) && equals(p.next, q.next); return false; } //以下是第8章习题 public boolean replace(Object obj, E element)//将元素值为obj的结点值替换为element,O(n) { //若替换成功返回true,否则返回false if (obj==null || element==null) return false; Node p=this.head; while (p!=null) { if (obj.equals(p.data)) { p.data = element; return true; } p = p.next; } return false; } public boolean replaceAll(Object obj, E element) //将所有元素值为obj的结点值替换为element,O(n) { //若替换成功返回true,否则返回false boolean done=false; if (obj!=null && element!=null) { Node p=this.head; while (p!=null) { if (obj.equals(p.data)) { p.data = element; done = true; } p = p.next; } } return done; } public boolean removeAll(Object obj) //将所有元素值为obj的结点删除 { if (this.head==null || obj==null) return false; boolean done=false; while (this.head!=null && obj.equals(this.head.data)) { this.head = this.head.next; //头删除 done = true; } Node front=this.head, p=front.next; while(p!=null) { if (obj.equals(p.data)) { front.next = p.next; //删除p结点 p = front.next; done = true; } else { front = p; p = p.next; } } return done; } public static void main(String[] args) { String[] letters={"A","B","C","D","E","F"}; SinglyLinkedList list1 = new SinglyLinkedList (letters); SinglyLinkedList list2 = new SinglyLinkedList (list1); list2.copy(list1); System.out.println(list2.toString()); System.out.println("equals(), "+list2.equals(list1)); } } /* 程序运行结果如下: (A, B, C, D, E, F) */ /* 第2章 //可行,但效率低, 时间复杂度是O(n*n)。 public String toString() { String str="{"; if (this.length()!=0) { for(int i=0; i
其他回答
//单链表类 package datastructure.linearlist; import datastructure.linearlist.node; //导入单链表结点类 import java.util.iterator; //导入迭代器接口 public class singlylinkedlist<e> extends abstractlist<e> implements llist<e> //单链表类,实现线性表接口 { protected node<e> head; //头指针,指向单链表第1个结点 public singlylinkedlist() //构造空单链表 { this.head = null; } public singlylinkedlist(node<e> head) //构造指定头指针的单链表 { this.head = head; } public boolean isempty() //判断单链表是否为空,o(1) { return this.head==null; } public int length() //返回单链表长度 { //单链表遍历算法,o(n) int i=0; node<e> p=this.head; while (p!=null) { i++; p = p.next; } return i; } public e get(int index) //返回序号为index的对象,index初值为0 { //若单链表空或序号错误返回null,o(n) if (this.head!=null && index>=0) { int j=0; node<e> p=this.head; while (p!=null && j<index) { j++; p = p.next; } if (p!=null) return (e)p.data; } return null; } public e set(int index, e element) //设置序号为index的对象为element,o(n) { //若操作成功返回原对象,否则返回null if (this.head!=null && index>=0 && element!=null) { int j=0; node<e> p=this.head; while (p!=null && j<index) { j++; p = p.next; } if (p!=null) { e old = (e)p.data; p.data = element; return old; //若操作成功返回原对象 } } return null; //操作不成功 } public boolean add(int index, e element) //插入element对象,插入后对象序号为index { //若操作成功返回true,o(n) if (element==null) return false; //不能添加空对象(null) if (this.head==null || index<=0) //头插入 this.head = new node<e>(element, this.head); else //单链表不空且index>=1 { int j=0; node<e> p=this.head; while (p.next!=null && j<index-1) //寻找插入位置 { j++; p = p.next; } p.next = new node<e>(element, p.next);//中间/尾插入 } return true; } public boolean add(e element) //在单链表最后添加对象,重载,o(n) { return add(integer.max_value, element); } public e remove(int index) //移去序号为index的对象,o(n) { //若操作成功返回被移去对象,否则返回null e old = null; if (this.head!=null && index>=0) if (index==0) //头删除 { old = (e)this.head.data; this.head = this.head.next; } else //中间/尾删除 { int j=0; node<e> p=this.head; while (p.next!=null && j<index-1) //定位到待删除结点的前驱结点 { j++; p = p.next; } if (p.next!=null) { old = (e)p.next.data; //操作成功,返回原对象 p.next = p.next.next; //删除p的后继结点 } } return old; } public void clear() //清空单链表,o(1) { this.head = null; } public string tostring() //返回显示单链表所有元素值对应的字符串 { //单链表遍历算法,o(n) string str="("; node<e> p = this.head; while (p!=null) { str += p.data.tostring(); p = p.next; if (p!=null) str += ", "; } return str+")"; } //以上实现llist接口,第2章 //以下2.4 迭代器内容 public iterator<e> iterator() //返回一个迭代器对象 { return new itr(); } private class itr implements iterator<e> //私有内部类,实现迭代器接口 { private node<e> cursor = head; public boolean hasnext() //若有后继元素,返回true { return cursor!=null && cursor.next!=null; } public e next() //返回后继元素 { if (cursor != null && cursor.next!=null) { e element = cursor.next.data; cursor = cursor.next; return element; } return null; } public void remove() //不支持该操作 { throw new unsupportedoperationexception(); } }//内部类itr结束 //以下第8章 8.2.1 顺序查找,散列表中用 public node<e> search(e element, node<e> start) //从单链表结点start开始顺序查找指定对象 { //若查找成功返回结点,否则返回null if (this.head==null || element==null) return null; node<e> p=start; while (p!=null && !element.equals(p.data)) { system.out.print(p.data+"? "); p = p.next; } return p; } public node<e> search(e element) //顺序查找指定对象 { return search(element, head); } /* public boolean contain(e element) //以查找结果判断单链表是否包含指定对象 { //若包含返回true,否则返回false return this.search(element)!=null; } */ public boolean remove(e element) //移去首次出现的指定对象,o(n) { //若操作成功返回true if (this.head==null || element==null) return false; if (element.equals(this.head.data)) { this.head = this.head.next; //头删除 return true; } node<e> front=this.head, p=front.next; //中间/尾删除 while (p!=null && !element.equals(p.data)) { front = p; p=p.next; } if (p!=null) { front.next = p.next; return true; } return false; } //以下是第2章习题 public singlylinkedlist(e[] element) //由指定数组中的多个对象构造单链表 { this.head = null; if (element!=null && element.length>0) { this.head = new node(element[0]); node<e> rear=this.head; int i=1; while (i<element.length) { rear.next = new node(element[i++]); rear = rear.next; } } } public void concat(singlylinkedlist list) //将指定单链表list链接在当前单链表之后 { if (this.head==null) this.head = list.head; else { node<e> p=this.head; while (p.next!=null) p = p.next; p.next = list.head; } } public singlylinkedlist(singlylinkedlist<e> list) //以单链表list构造新的单链表 { //复制单链表 this.head = null; if (list!=null && list.head!=null) { this.head = new node(list.head.data); node<e> p = list.head.next; node<e> rear = this.head; while (p!=null) { rear.next = new node<e>(p.data); rear = rear.next; p = p.next; } } } //递归方法 // public singlylinkedlist(singlylinkedlist<e> list) //以单链表list构造新的单链表 public void copy(singlylinkedlist<e> list) //复制单链表 { this.head = copy(list.head); } private node<e> copy(node<e> p) //复制单链表,递归方法 { node<e> q=null; if (p!=null) { q = new node(p.data); q.next = copy(p.next); } return q; } /*//递归方法 public string tostring() { return "("+ this.tostring(this.head) +")"; } public string tostring(node<e> p) //递归方法 { if (p!=null) return p.data.tostring() + ", " + this.tostring(p.next); //递归调用 return ""; } public singlylinkedlist(e[] element) //由指定数组中的多个对象构造单链表 { this.head = null; if (element!=null) this.head = create(element,0); } private node<e> create(e[] element, int i) //由指定数组构造单链表 { //递归方法 node<e> p=null; if (i<element.length) { p = new node(element[i]); p.next = create(element, i+1); } return p; } */ public boolean equals(object obj) //比较两条单链表是否相等 { if (obj == this) return true; if (obj instanceof singlylinkedlist) { singlylinkedlist list = (singlylinkedlist)obj; return equals(this.head, list.head); } return false; } private boolean equals(node<e> p, node<e> q) //比较两条单链表是否相等,递归方法 { if (p==null && q==null) return true; if (p!=null && q!=null) return p.data.equals(q.data) && equals(p.next, q.next); return false; } //以下是第8章习题 public boolean replace(object obj, e element)//将元素值为obj的结点值替换为element,o(n) { //若替换成功返回true,否则返回false if (obj==null || element==null) return false; node<e> p=this.head; while (p!=null) { if (obj.equals(p.data)) { p.data = element; return true; } p = p.next; } return false; } public boolean replaceall(object obj, e element) //将所有元素值为obj的结点值替换为element,o(n) { //若替换成功返回true,否则返回false boolean done=false; if (obj!=null && element!=null) { node<e> p=this.head; while (p!=null) { if (obj.equals(p.data)) { p.data = element; done = true; } p = p.next; } } return done; } public boolean removeall(object obj) //将所有元素值为obj的结点删除 { if (this.head==null || obj==null) return false; boolean done=false; while (this.head!=null && obj.equals(this.head.data)) { this.head = this.head.next; //头删除 done = true; } node<e> front=this.head, p=front.next; while(p!=null) { if (obj.equals(p.data)) { front.next = p.next; //删除p结点 p = front.next; done = true; } else { front = p; p = p.next; } } return done; } public static void main(string[] args) { string[] letters={"a","b","c","d","e","f"}; singlylinkedlist<string> list1 = new singlylinkedlist<string>(letters); singlylinkedlist<string> list2 = new singlylinkedlist<string>(list1); list2.copy(list1); system.out.println(list2.tostring()); system.out.println("equals(), "+list2.equals(list1)); } } /* 程序运行结果如下: (a, b, c, d, e, f) */ /* 第2章 //可行,但效率低,时间复杂度是o(n*n)。 public string tostring() { string str="{"; if (this.length()!=0) { for(int i=0; i<this.length()-1; i++) str += this.get(i).tostring()+", "; str += this.get(this.length()-1).tostring(); } return str+"}"; } */
相关问答
更多-
java中LinkedList的问题[2023-07-21]
//单链表类 package dataStructure.linearList; import dataStructure.linearList.Node; //导入单链表结点类 import java.util.Iterator; //导入迭代器接口 public class SinglyLinkedList extends AbstractList implements LList //单链表类,实现 线性表接口 { protected Node head; //头指针,指向单链表第1个结点 publi ... -
java中LinkedList的问题[2023-05-29]
//单链表类 package dataStructure.linearList; import dataStructure.linearList.Node; //导入单链表结点类 import java.util.Iterator; //导入迭代器接口 public class SinglyLinkedListextends AbstractList implements LList //单链表类,实现线性表接口 { protected Node head; //头指针,指向 ... -
Java LinkedList中的indexOf查找的问题[2023-05-21]
这个方法是可行的的,indexOf方法 比较的是通过equal方法比较的 如果你重写了equal方法,就使用你的规则进行比较,否则使用系统默认的方法即 Object中的equal方法; 给你贴个demo; public class Main{ public static void main(String[] args) { LinkedList list = new LinkedList<>(); Book a = new Book(1,"a"); Book b = new Book(2,"b"); Boo ... -
我的问题是为什么Java调用这个数据结构LinkedList,而它不是一个真正的链表? 因为它的实现是一个链表。 从文档 : List和Deque接口的双链表实现。 实现所有可选的列表操作,并允许所有元素(包括null )。 LinkedList是一个通过LinkedList实现的List , ArrayList是一个使用数组实现的List 。等等。根据运行时特性,您选择哪一个可能很重要。 例如,从LinkedList文档: 所有这些操作的执行情况可能与双向链表相符。 索引到列表中的操作将从开始或结束遍历列 ...
-
你有没有看过Stroustrup的会议讨论视频,他表明你应该使用std::vector除非你已经测量了不使用std::vector的性能优势? 他表明std::vector几乎总是使用正确的集合,并且表明即使在中间插入和删除它也比链表更快。 现在将其转换为Java:使用ArrayList除非您用其他东西测量了更好的性能。 这是为什么? 使用现代处理器体系结构,可以获得一个位置优势:您比较的元素,您一起处理的元素,都在内存中彼此相邻存储,并且可能同时位于CPU的缓存中。 这使得它们的获取和写入速度比它们在主存 ...
-
因为您在弧中设置静态变量。 静态变量是类变量,而不是实例变量。 所以arc的所有实例都会为类变量赋予相同的值。 尝试这个: public static class arc { public int start; public int end; } 实际上相同的元素没有插入列表中,两个不同的元素(实例)正在列表中插入,但是您从两个实例中打印类变量值。 Because you are setting static variable in arc. static ...
-
Java中的方法参数始终按值传递。 这可能有点令人困惑,因为对象总是通过引用访问,所以你可能会认为它们是通过引用传递的; 但他们不是。 相反,引用按值传递。 这意味着什么,这样的方法: public void methodThatDoesNothing(Object dst, Object src) { src = dst; } 实际上什么也没做 它修改其局部变量src以引用与局部变量dst相同的对象,但这些只是在函数返回时消失的局部变量。 它们完全独立于传递给方法的任何变量或表达式。 所以,在你 ...
-
问题似乎出现在这段代码中: Link linkCurr = head; if (head != null) { for (int i = 0; i < size; ++i) { if (obj.equals(linkCurr.getData())){ linkCurr.setNext(linkCurr.getNext().getNext()); size--; ...
-
while(!linkedList.isEmpty()){ linkedList.peek(); } peek()永远不会将链表从非空变为空,因为它不会更改列表。 但据我所知,没有涉及循环 你觉得怎么样? while(!linkedList.isEmpty()){ linkedList.peek(); } peek() will never change a linked list from nonempty to empty, since it d ...
-
LinkedList是一个List ,但它也是Deque ,它也是一个Queue 。 这3个接口提供功能变化。 例如, element和peek在Queue中定义,但是如果没有要返回的值,则另一个返回特殊值而另一个则抛出异常。 peekFirst特定于Deque ,因为Deque可以从两端peeked 。 同样的原则适用于其他方法。 (add vs offer是返回vs异常的问题,offerFirst是Deque特定方法......)。 不过,我同意Deque界面有点奇怪。 它通过强制实现实现方法的Queu ...