Data Structure Lab Final
Data Structure Lab Final
Reg-No:SP19-BCS-036
Section: 4B
Singly Linked List
Program 1:
public class LinkedListProgram1<T> {
node.setNext(first);
first = node;
if(first.getNext()!=null)
first = first.getNext();
if(node.getNext()!=null) printList(node.getNext());
printList(first);
}
public static void main(String[] args) {
list.insert(new LinkedListNode<String>("Manish"));
list.insert(new LinkedListNode<String>("Pandit"));
list.insert(new LinkedListNode<String>("Tanvi"));
list.insert(new LinkedListNode<String>("Monika"));
list.print();
list.remove();
list.print();
class LinkedListNode<T> {
private T value;
this.value = value;
this.next = next;
}
public LinkedListNode<T> getNext() {
return next;
public T getValue() {
return value;
Program 2:
public class SinglyLinkedListProgram2 {
s.addAtFrontNode("c");
s.addAtEndNode("x");
s.addAtFrontNode("b");
s.addAtEndNode("y");
s.addAtFrontNode("a");
s.addAtEndNode("z");
s.reset();
while (s.hasNext()) {
System.out.print(s.next());
System.out.println();
System.out.println(s.countNodes());
System.out.println(check.toString());
*/
public SinglyLinkedList() {
head_ptr = null;
tail_ptr = null;
countNodes = 0;
iter = null;
*/
countNodes++;
if (head_ptr == null) {
head_ptr = head;
tail_ptr = head_ptr;
else {
tail_ptr.setLink(head);
tail_ptr = head;
countNodes++;
if (head_ptr == null) {
head_ptr = head;
tail_ptr = head_ptr;
} else {
head.setLink(head_ptr);
head_ptr = head;
*/
display = cursor.data.toString();
System.out.print(display);
}
return display;
*/
ObjectNode o = null;
int count = 0;
if (i < countNodes()) {
o = head_ptr;
if (i == 0) {
return o.getData();
} else {
while (count != i) {
o = o.link;
count++;
return o.getData();
}
*/
iter = head_ptr;
/* Returns the boolean value based on whether the next node exists
*/
return b;
/*
*/
Object nextNodeData;
if (iter == null)
iter = head_ptr;
nextNodeData = iter.data;
iter = iter.link;
return nextNodeData;
/*
*/
return countNodes;
/*
*/
return tail_ptr;