Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Lista {
- protected Node head;
- protected Node tail;
- protected long size;
- public Lista(){
- head = null;
- tail = null;
- size = 0;
- }
- public void insereInicio(Node n){
- n.setProximo(head);
- head = n;
- size += 1;
- if(size==1){
- tail = n;
- }
- }
- public void insereFim(Node n){
- tail.setProximo(n);
- tail = n;
- size = size + 1;
- if(size==1){
- head = n;
- }
- }
- public boolean removeInicio() {
- if(size!=0) {
- head = head.getProximo();
- size -=1;
- return true;
- }
- else {
- System.out.println("Lista vazia.");
- return false;
- }
- }
- public boolean removeFim() {
- if(size!=0) {
- Node n = head;
- int i;
- for(i=1;i<size-1;i++) {
- n = n.getProximo();
- }
- System.out.println(i+" iteraçáes.\n");
- tail = n;
- tail.setProximo(null);
- size -=1;
- return true;
- }
- else {
- System.out.println("Lista vazia.");
- return false;
- }
- }
- public boolean busca(int valor) {
- if(size==0) return false;
- Node n = head;
- for(int i=1;i<=size;i++) {
- if(valor==n.getValor()) {
- return true;
- }
- else {
- n = n.getProximo();
- }
- }
- return false;
- }
- public Node getHead() {
- return head;
- }
- public void setHead(Node head) {
- this.head = head;
- }
- public Node getTail() {
- return tail;
- }
- public void setTail(Node tail) {
- this.tail = tail;
- }
- public long getSize() {
- return size;
- }
- public void setSize(long size) {
- this.size = size;
- }
- public String toString(){
- Node cursor;
- cursor = head;
- while(cursor != null){
- System.out.println(cursor.getValor());
- cursor = cursor.getProximo();
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment