Implement a code for Students information using linked list Such as student name Registration no and cgpa Write client code to retain data of students who have greater than 1.3 cgpa and also delete the record of students whose less than 1.3 CGPA java code
public class LinkedList {
private Node head;
private Node tail;
public boolean add(Student student) {
Node node = new Node(student);
if (head == null) {
head = node;
} else {
tail.setNext(node);
}
tail = node;
return true;
}
public void filter() {
if (head != null) {
Node cur = head;
while (cur != null) {
if (cur.getData().getCgpa() < 1.3) {
head = cur.getNext();
if (head == null) {
tail = null;
}
} else if (cur.getNext() != null) {
if (cur.getNext().getData().getCgpa() < 1.3) {
if (cur.getNext().getNext() == null) {
tail = cur;
cur.setNext(null);
} else {
cur.setNext(cur.getNext().getNext());
}
}
}
cur = cur.getNext();
}
}
}
}
public class Node {
private Node next;
private Student data;
public Node(Student data) {
this.data = data;
}
public Student getData() {
return data;
}
public void setData(Student data) {
this.data = data;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}
public class Student {
private int registrationNumber;
private String name;
private double cgpa;
public Student(int registrationNumber, String name, double cgpa) {
this.registrationNumber = registrationNumber;
this.name = name;
this.cgpa = cgpa;
}
public int getRegistrationNumber() {
return registrationNumber;
}
public String getName() {
return name;
}
public double getCgpa() {
return cgpa;
}
public void setRegistrationNumber(int registrationNumber) {
this.registrationNumber = registrationNumber;
}
public void setName(String name) {
this.name = name;
}
public void setCgpa(double cgpa) {
this.cgpa = cgpa;
}
}
Comments
Dear Sawaira, You're welcome. We are glad to be helpful. If you liked our service please press like-button beside answer field. Thank you!
Thank you so much
Leave a comment