Data structure

profileIstudyhelp_sa
JUBAILUNIVERSITYCOLLEGE.docx

JUBAIL UNIVERSITY COLLEGE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

SEMESTER 382

GROUP ASSIGNMENT (8%)

Course Code

CS 205

Course Title

Data Structures

Section

Date Given

26/03/2018

Date of Submission

PART I

TO BE FILLED BY THE STUDENT

STUDENT’S NAME

ID. No.

STUDENT’S NAME

ID. No.

STUDENT’S NAME

ID. No.

TO BE FILLED BY THE CONCERNED DEPARTMENT

PART II

1st Marker

Area of Assessment

Max Marks

Actual Marks

Comments/Remarks

Project Documentation

10

System Functionality

18

Presentation

4

Total

32

Name:

Signature

:

Introduction

PROJECT DESCRIPTION

The students need to form groups consisting of 3 members. Each group has to develop TWO (2) Java applications by applying any suitable Data Structures (Linked List, Stack and Queue) studied in this course. The applications can be developed for handling the student list, employee list, shopping list, book list, seminar reservation, hall reservation, air-ticket reservation, hotel reservation, stock inventory, sales invoice or any other. The nodes of each data structure should include at least FOUR (4) fields/attributes appropriate to the applications. Each application should include at least FOUR (4) basic operations performed on the data structures (such as insert, update, delete, search or print). And, include at least ONE (1) new operation/method in each application. (For example, sorting the elements (in ascending/descending order) in the linked list, retrieving/modifying the set of nodes in the list that satisfies the given condition, deleting the set of nodes from the list that satisfies the given condition, adding/removing the elements as per priority in the queue, swapping the elements in the Stack etc.)

Application of Linked List.

In computer a linked list is a linear collection of data elements in which a linear order is not given by their physical placement in memory. Instead, each element points to the next.

Program listing

Main Class

public class Link {

// Set to public so getters & setters aren't needed

public String bookName;

public int booksSold;

public Link next;

public Link(String bookName, int booksSold){

this.bookName = bookName;

this.booksSold = booksSold;

}

public void display(){

System. out .println(bookName + ": " + booksSold + ",000,000 Sold");

}

public String toString(){

return bookName;

}

public static void main(String[] args) {

LinkList theLinkedList = new LinkList();

theLinkedList.insertFirstLink("Don Quixote", 500);

theLinkedList.insertFirstLink("A Tale of Two Cities", 200);

theLinkedList.insertFirstLink("The Lord of the Rings", 150);

theLinkedList.insertFirstLink("Harry Potter and the Sorcerer's Stone", 107);

theLinkedList.display();

System. out .println("Value of first in LinkedList " + theLinkedList.firstLink + "\n");

// Removes the last Link entered

theLinkedList.removeFirst();

theLinkedList.display();

System. out .println(theLinkedList.find("The Lord of the Rings").bookName + " Was Found");

theLinkedList.removeLink("A Tale of Two Cities");

System. out .println("\nA Tale of Two Cities Removed\n");

theLinkedList.display();

}

}

Linked List Class

class LinkList{

public Link firstLink;

LinkList(){

// Here to show the first Link always starts as null

firstLink = null;

}

// Returns true if LinkList is empty

public boolean isEmpty(){

return(firstLink == null);

}

public void insertFirstLink(String bookName, int booksSold){

Link newLink = new Link(bookName, booksSold);

// Connects the firstLink field to the new Link

newLink.next = firstLink;

firstLink = newLink;

}

public Link removeFirst(){

Link linkReference = firstLink;

if(!isEmpty()){

// Removes the Link from the List

firstLink = firstLink.next;

} else {

System. out .println("Empty LinkedList");

}

return linkReference;

}

public void display(){

Link theLink = firstLink;

// Start at the reference stored in firstLink and

while(theLink != null){

theLink.display();

System. out .println("Next Link: " + theLink.next);

theLink = theLink.next;

System. out .println();

}

}

public Link find(String bookName){

Link theLink = firstLink;

if(!isEmpty()){

while(theLink.bookName != bookName){

// Checks if at the end of the LinkedList

if(theLink.next == null){

// Got to the end of the Links in LinkedList

// without finding a match

return null;

} else {

// Found a matching Link in the LinkedList

theLink = theLink.next;

}

}

} else {

System. out .println("Empty LinkedList");

}

return theLink;

}

public Link removeLink(String bookName){

Link currentLink = firstLink;

Link previousLink = firstLink;

// Keep searching as long as a match isn't made

while(currentLink.bookName != bookName){

// Check if at the last Link in the LinkedList

if(currentLink.next == null){

// bookName not found so leave the method

return null;

} else {

// We checked here so let's look in the

// next Link on the list

previousLink = currentLink;

currentLink = currentLink.next;

}

}

if(currentLink == firstLink){

// If you are here that means there was a match

// in the reference stored in firstLink in the

// LinkedList so just assign next to firstLink

firstLink = firstLink.next;

} else {

// If you are here there was a match in a Link other

// than the firstLink. Assign the value of next for

// the Link you want to delete to the Link that's

// next previously pointed to the reference to remove

System. out .println("FOUND A MATCH");

System. out .println("currentLink: " + currentLink);

System. out .println("firstLink: " + firstLink);

previousLink.next = currentLink.next;

}

return currentLink;

}

}

Sample Output

References

Treehouse.com

Eclipseide.org

www.quora.com

1

1

1

1

JUBAIL UNIVERSITY COLLEGE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

SEMESTER 382

GROUP ASSIGNMENT (8%)

Course Code

CS 205

Course Title

Data Structures

Section

Date Given

26/03/2018

Date of Submission

PART I

TO BE FILLED BY THE STUDENT

STUDENT’S NAME

ID. No.

STUDENT’S NAME

ID. No.

STUDENT’S NAME

ID. No.

TO BE FILLED BY THE CONCERNED DEPARTMENT

PART II

1

st

Marker

Area of Assessment

Max

Marks

Actual

Marks

Comments/Remarks

Project Documentation

10

System Functionality

18

Presentation

4

Total

32

Name:

1

JUBAIL UNIVERSITY COLLEGE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

SEMESTER 382

GROUP ASSIGNMENT (8%)

Course Code CS 205 Course Title Data Structures Section

Date Given 26/03/2018 Date of Submission

PART I TO BE FILLED BY THE STUDENT

STUDENT’S NAME ID. No.

STUDENT’S NAME ID. No.

STUDENT’S NAME ID. No.

TO BE FILLED BY THE CONCERNED DEPARTMENT

PART II 1

st

Marker

Area of Assessment Max

Marks

Actual

Marks

Comments/Remarks

Project Documentation 10

System Functionality 18

Presentation 4

Total 32

Name: