Android Open Source - androidcodes Linked List Impl






From Project

Back to project page androidcodes.

License

The source code is released under:

GNU General Public License

If you think the Android project androidcodes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lists;
/*from w w  w . j  a va  2  s.c om*/
public class LinkedListImpl<E> {

  private class Node<E> {
    private E data;
    private Node<E> next;

    public Node(E data, Node<E> next) {
      this.data = data;
      this.next = next;

    }

    public Node(E data) {
      this.data = data;
      this.next = null;
    }

    /**
     * @return the data
     */
    public E getData() {
      return data;
    }

    /**
     * @param data
     *            the data to set
     */
    public void setData(E data) {
      this.data = data;
    }

    /**
     * @return the next
     */
    public Node<E> getNext() {
      return next;
    }

    /**
     * @param next
     *            the next to set
     */
    public void setNext(Node<E> next) {
      this.next = next;
    }

  }

  private Node<E> head;
  private int listCount;

  public LinkedListImpl() {
    head = new Node<E>(null);
    listCount = 0;

  }

  public void add(E data) {
    Node<E> nodeTemp = new Node<E>(data);
    Node<E> current = head;
    while (current.next != null) {
      current = current.getNext();
    }
    current.setNext(nodeTemp);
    nodeTemp.setNext(null);
    listCount++;

  }

  public void addAtPos(E data, int pos) {
    Node<E> current = head;
    Node<E> nodeTemp = new Node<E>(data);
    for (int i = 0; i < pos; i++) {
      current = current.getNext();
    }

    nodeTemp.setNext(current.getNext());
    current.setNext(nodeTemp);
    listCount++;

  }

  public boolean remove(int pos) {
    Node<E> current = head;
    if (current == null || current.getNext() == null || listCount < pos) {
      System.out.println("error");
      return false;
    }
    for (int i = 0; i < pos; i++) {
      current = current.getNext();
    }
    current.setNext(current.getNext().getNext());
    listCount--;
    return true;

  }

  public E get(int pos) {
    Node<E> current = head;
    if (listCount < pos || pos < 0) {
      System.out.println("error");
      return null;
    }
    for (int i = 0; i < pos; i++) {
      current = current.getNext();
    }
    return (E) current;

  }

  public int getSize() {
    return listCount;

  }

  public Node<E> reverseList(Node<E> node) {
    if (node == null || node.next == null) {
      return node;
    }
    Node<E> currentNode = node;
    Node<E> previousNode = null;
    Node<E> nextNode = null;

    while (currentNode != null) {
      nextNode = currentNode.next;
      currentNode.next = previousNode;
      previousNode = currentNode;
      currentNode = nextNode;
    }
    return previousNode;
  }

  public static void main(String[] args) {
    // TODO Auto-generated method stub

  }

}




Java Source Code List

com.app.citypediav2.Constants.java
com.app.citypediav2.CustomButton.java
com.app.citypediav2.CustomEditText.java
com.app.citypediav2.CustomText.java
com.app.citypediav2.DetailsActivity.java
com.app.citypediav2.ItemListActivity.java
com.app.citypediav2.ItemListAdapter.java
com.app.citypediav2.ListAdapterOptions.java
com.app.citypediav2.MainActivity.java
com.app.citypediav2.MainApplication.java
com.app.citypediav2.Options.java
com.app.citypediav2.receivers.BootCompletedBroadcastReceiver.java
com.app.citypediav2.receivers.ConnectionChangeReceiver.java
com.app.citypediav2.services.DataLoggingService.java
com.app.citypediav2.utils.AppUtils.java
com.app.citypediav2.utils.ArticleTextExtractor.java
com.app.citypediav2.utils.Constants.java
com.app.citypediav2.utils.LogUtils.java
com.app.citypediav2.utils.PrefUtils.java
com.app.twitterclient.model.TwitterBackend.java
com.app.twitterclient.utils.AppUtils.java
com.app.twitterclient.utils.ConnectionDetector.java
com.app.twitterclient.utils.ConsumerKeyConstants.java
com.app.twitterclient.utils.LogUtils.java
com.app.twitterclient.view.BootActivity.java
com.app.twitterclient.view.HomeActivity.java
com.app.twitterclient.view.NewAccountActivity.java
com.app.twitterclient.view.TwitterAuthActivity.java
com.binarysearch.BinarySearch.java
com.citypedia.app.enities.Atms.java
com.citypedia.app.enities.Cabs.java
com.citypedia.app.enities.Gyms.java
com.citypedia.app.enities.PetrolPumps.java
com.citypedia.app.enities.PlacesToVisit.java
com.citypedia.app.enities.Restaurants.java
com.citypedia.app.providers.CityDB.java
com.citypedia.app.providers.CityPediaProvider.java
com.citypedia.app.providers.ContentDescriptor.java
com.info.magazine.MainActivity.java
com.java.thread.ConditionExample.java
com.java.thread.DeadLock.java
com.java.thread.Main.java
com.java.thread.ProdConsumerProb.java
com.java.thread.SampleThread.java
com.java.thread.package-info.java
com.lists.LinkedListImpl.java
com.pract.threadpool.CustomQueue.java
com.pract.threadpool.MyQueue.java
com.pract.threadpool.TestThreadPoolManager.java
com.pract.threadpool.ThreadPoolManager.java
com.pract.threadpool.Worker.java
com.queues.QueuesImpl.java
com.rjil.logcollector.DeviceBroadcastReceiver.java
com.rjil.logcollector.LogCollectorService.java
com.rjil.logcollector.LogDumper.java
com.sorting.InsertionSort.java
com.sorting.package-info.java
com.stacks.BracketChecker.java
com.stacks.StackImpl.java
com.stacks.StockSpan.java