import java.util.*;
public class MyLinkedList {
private Node head;
private class Node {
private String element;
Node link;
}
public MyLinkedList() {
head=null;
}
public void insertAtHead(String ele) {
Node curr = new Node();
curr.element = ele;
curr.link = head;
head=curr;
}
public void insertAtTail(String ele) {
Node curr = new Node();
curr.element = ele;
curr.link = head;
head=curr;
}
public void removeAtHead(String ele) {
Node curr = new Node();
curr.element = ele;
curr.link = head;
head=curr;
}
public void removeAtTail(String ele) {
Node curr = new Node();
curr.element = ele;
curr.link = head;
head=curr;
}
public static void main(String[] args) {
MyLinkedList s1 = new MyLinkedList();
s1.insertAtHead("Java I");
s1.insertAtTail("Java II");
s1.insertAtTail("Data Structure");
System.out.println(s1);
System.out.println(s1.removeAtHead ());
System.out.println(s1);
s1.insertAtHead("CISC120");
System.out.println(s1);
s1.insertAtTail("Android");
System.out.println(s1);
System.out.println(s1.removeAtTail ());
System.out.println(s1);
for (Node x = s1.head; x!=null; x = x.link)
System.out.println (x.element + "\t");
}
}
s1lkman 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Taywin 312 Posting Virtuoso
s1lkman 0 Newbie Poster
s1lkman 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Taywin 312 Posting Virtuoso
s1lkman 0 Newbie Poster
Taywin 312 Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.