-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
assignment 7 completed, major changes expected to occur in future
- Loading branch information
1 parent
f19939d
commit 2294953
Showing
5 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
public class LinkedList | ||
{ | ||
Node head; | ||
LinkedList() | ||
{ | ||
head=null; | ||
} | ||
//Insertion | ||
public void add(int data) | ||
{ | ||
Node t=head; | ||
if(head==null) | ||
{ | ||
head = new Node(data); | ||
} | ||
else | ||
{ | ||
while(t.next!=null) | ||
{ | ||
t=t.next; | ||
} | ||
t.next= new Node(data); | ||
} | ||
} | ||
//Deletion | ||
public void del() | ||
{ | ||
if(head==null) | ||
System.out.println("Stack Underflow"); | ||
else | ||
head=head.next; | ||
} | ||
public void DelEnd() | ||
{ | ||
int len=this.count(); | ||
len=len-1; | ||
Node n=head; | ||
int c=0; | ||
while(n.next!=null) | ||
{ | ||
c++; | ||
if(c==len) | ||
break; | ||
n=n.next; | ||
} | ||
n.next=null; | ||
} | ||
public int count() | ||
{ | ||
int c=0; | ||
Node n=head; | ||
while(n.next!=null) | ||
{ | ||
c++; | ||
n=n.next; | ||
} | ||
c++; | ||
return c; | ||
} | ||
public void display() | ||
{ | ||
Node n=head; | ||
if(n==null) | ||
System.out.println("Queue is Empty"); | ||
else | ||
{ | ||
while(n.next!=null) | ||
{ | ||
System.out.println(n); | ||
n=n.next; | ||
} | ||
System.out.println(n); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
public class Node | ||
{ | ||
protected Node next; | ||
protected int data; | ||
|
||
Node() | ||
{ | ||
next=null; | ||
} | ||
Node(int data) | ||
{ | ||
this.data=data; | ||
next=null; | ||
} | ||
int getdata() | ||
{ | ||
return data; | ||
} | ||
public String toString() | ||
{ | ||
return data+""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.util.*; | ||
public class part1 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
queue q = new queue(5); | ||
Scanner in = new Scanner(System.in); | ||
while(true) | ||
{ | ||
System.out.println("***MENU***"); | ||
System.out.println("0: Exit"); | ||
System.out.println("1: Insert"); | ||
System.out.println("2: Delete"); | ||
System.out.println("3: Display"); | ||
System.out.println("Enter your choice"); | ||
int choice=in.nextInt(); | ||
switch(choice) | ||
{ | ||
case 0: | ||
System.exit(0); | ||
case 1: | ||
System.out.print("Enter the value to insert :"); | ||
int i=in.nextInt(); | ||
q.insert(i); | ||
break; | ||
case 2: | ||
q.delete(); | ||
break; | ||
case 3: | ||
q.display(); | ||
break; | ||
default: | ||
System.out.println("Invalid choice"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.util.*; | ||
public class part2 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
LinkedList q = new LinkedList(); | ||
while(true) | ||
{ | ||
System.out.println("***MENU***"); | ||
System.out.println("0: Exit"); | ||
System.out.println("1: Insert"); | ||
System.out.println("2: Delete"); | ||
System.out.println("3: Display"); | ||
System.out.println("Enter your choice"); | ||
int choice=in.nextInt(); | ||
switch(choice) | ||
{ | ||
case 0: | ||
System.exit(0); | ||
case 1: | ||
System.out.print("Enter the value to insert :"); | ||
int i=in.nextInt(); | ||
q.add(i); | ||
break; | ||
case 2: | ||
q.del(); | ||
break; | ||
case 3: | ||
q.display(); | ||
break; | ||
default: | ||
System.out.println("Invalid choice"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
public class queue | ||
{ | ||
int Q[]; | ||
int rear, front; | ||
|
||
queue(int n) | ||
{ | ||
Q = new int[n]; | ||
rear=0; | ||
front=0; | ||
} | ||
public void insert(int i) | ||
{ | ||
if(front==Q.length) | ||
System.out.println("Stack Overflow"); | ||
else | ||
{ | ||
Q[front]=i; | ||
front++; | ||
} | ||
} | ||
public void delete() | ||
{ | ||
if(front==rear) | ||
System.out.println("Stack Underflow"); | ||
else | ||
rear++; | ||
} | ||
public void display() | ||
{ | ||
for(int i=rear; i<front; i++) | ||
{ | ||
System.out.println(Q[i]); | ||
} | ||
} | ||
public boolean is_full() | ||
{ | ||
return front==Q.length-1; | ||
} | ||
public boolean is_empty() | ||
{ | ||
return front==rear; | ||
} | ||
} |