Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
5 views
DS Using Java Lab (University Program)
Data Structure using Java lab
Uploaded by
dead wish
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save DS using Java lab(university program) For Later
Download
Save
Save DS using Java lab(university program) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
5 views
DS Using Java Lab (University Program)
Data Structure using Java lab
Uploaded by
dead wish
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save DS using Java lab(university program) For Later
Carousel Previous
Carousel Next
Save
Save DS using Java lab(university program) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 11
Search
Fullscreen
LIST OF EXERCISES: 1. Write @ Java programs to implement the List ADT using arrays and linked lists. 2.Write ¢ Java programs to implement the following using a singly linked list. Stack ADT (b) Queue ADT 3. Write @ java program that reads an infix expression, converts the expression to postfix form and then evaluates the postfix expression (use stack ADT). 4, Write @ Java program to implement priority queue ADT. 5.Write a Java program to perform the following operations: (a) _ Insert an element into a binary search tree. (b) Delete an element from a binary search tree. (©) Search for a key element in a binary search tree. 6. Write 2 Java program to pe-form the following operations (a) _ Insertion into an AVL-tree (b) Deletion from an AVL-tree 7.Write e Java programs for the implementation of BFS for a given graph. 8. Write a Java programs for the implementation of DFS for a given graph 9. Write a Java programs for implementing the following searching methods: (a) Linear search (b) Binary search. 10. Write a Java programs for implementing the following sorting methods (a) Bubble sort (b) Selection sort (c) _ Insertion sort (d) Radix sort.1.Write a Java programs to implement the List ADT using arrays and linked lists. a) ADT using arrays leave two page space b) Linked List public class singlyLinkedList { //Represent a node of the singly linked list class Node{ int data; Node next; public Node(int data) { this.data = data; this.next = null; } } //Represent the head and tail of the singly linked list, public Node head = null; public Node tail = null; /faddNode() will add a new nodeto thelist public void addNode(int data) { 1/Create anew node Node newNode = new Node(data); 1/Checks if the list is empty if(head == null) { /{Mf list is empty, both head end tail will point to new node head = newNode; tail = newNode; } else { //newNode will be added after tail such that tail’s next will point to newNode tail.next = newNode; //newNode will become new tail of the list tail = newNode; } } //display() will display all the nodes present in thelist public void display) { //Node current will point to head Node current = head; if(head == null) { System out printin(’List is empty"); return; }System.out.printin(’Nodes of singly linked list: "); while(current != null) { /|Prints each node by incrementing pointer System out print(current.data +"); current = current.next, } System. out printinO; } public static void main(Stingl] args) { singlyLinkedList sList = new singlyLinkedList0; //sListaddNode(; Add nodes to the list sList.addNode(1); sList.addNode(2); sList.addNode(3), sList.addNode(4); //Displays the nodes present in the list sList.display(); } } 2.Write a Java programs to implement the following using a singly linked list. Stack ADT (b) Queue ADT a)Stack ADT import java.io.*; import java.util; class StkList { StackNode root; static class StackNode { int data; StackNode next; StackNode(int data) {this.data = data; } } public void push(int data) { StackNode newNode = new StackNode(data);if (root == null) { root = newNode; } else { StackNode temp = root; root = newNode; newNode.next = temp; } System out printin(data +" pushed to stack’); } public void pop() { int popped = Integer. MIN_VALUE; if (Foot == null) { System.out.printin('Stack is Empty"); } else { popped = root.data; root = root next; } System out printin("\n the element popped fram stack\n"+popped); } void display() { if (root == null) ‘ystem out printin(‘Stack is empty’); } StackNode tmp1=root; while(tmpt!= null) { System.out print(tmp1.data+'\n’); imp1=tmp1.next; } }class stklinked public static void main(String[] args)throws IOException BufferedReader br=new BufferedReader{new InputStreamReadeSystem.in)); StkList s = new StkList(); int ch ; do { System.out.printin(‘\n1 push’); System. out printin('2.pop"); System. out printin('3.cisplay’); System.out printin(‘enter your choice\n’); ch =Integer.parseint(br.readLine()); switch(ch) { casel int x=Integer parselnt(brreadLine(); spush(x); break; case 2: s.pop0); break case 3: s.cisplay(; break default: System.out.printin(‘invalid choice’); break; } Jwhile(ch>=1&&ch<=3); } } b)Queue ADT class QNode { int key; QNode next;// constructor to create a new linked list node public QNode(int key) { this.key = key; this.next = null; } } class Queue { QNode front, rear; public Queue() { this.front = this.rear = null; } // Method to add an key to the queue. void enqueue(int key) { // Create a new LL node QNode temp = new QNode(key); // |i queue is empty, then new node is front and rear both if (this.rear == null) { thisfront = this.rear = temp; return; } // Add the new node at the end of queue and change rear this.rearnext = temp; this.rear = temp; } // Method to remove an key from queue. void dequeue() { //|f queue is empty, return NULL. if (this front == null) return; // Store previous front and move front one node ahead QNode temp = this.front this.front = this.front.next, // Kf front becomes NULL, then change rear also as NULL if (this front == null) this.rear= null;/! Driver class public class queuelinked{ public static void main(Stringl] args) { Queue q = new Queue(); q.enqueue(10); g.enqueue(20); a.dequeue(); g.dequeue(); g.enqueue(30); a.enqueue(40); g.enqueue(50); q.dequeue(); System. out printin("Queue Front :' + q.front key); System. out printin("‘Queue Rear : "+ q.rear key); 3.Write a java program that reads an infix expression, converts the expression to postfix form and then evaluates the postfix expression (use stack ADT). import java.util. Stack, import java.io*; class Test { // utility function to return // precedence of a given operator // Higher returned value means // higher precedence static int Preo(char ch) { switch (ch) { case '+': case“! return 1; case* case'/' return 2; case" return 3; } return -1; } // The main method that converts // given infix expression// 10 postfix expression String infixToPostfix(String exp) { // initializing empty String for result String result = new Strin // initializing empty stack Stack
stack = new Stacko(); for (inti = 0; i
stack=new Stack<>(); for(int i=O;i
You might also like
Data Structures Using Java - Lab Manual
PDF
83% (6)
Data Structures Using Java - Lab Manual
48 pages
algorithm-1
PDF
No ratings yet
algorithm-1
6 pages
Stack Using Arrays
PDF
No ratings yet
Stack Using Arrays
12 pages
Csit 365
PDF
No ratings yet
Csit 365
24 pages
2379
PDF
No ratings yet
2379
8 pages
DSA File
PDF
No ratings yet
DSA File
24 pages
Bda
PDF
No ratings yet
Bda
20 pages
Hadoop Lab Manual
PDF
No ratings yet
Hadoop Lab Manual
46 pages
Unit1 Hadoop
PDF
No ratings yet
Unit1 Hadoop
20 pages
MENU 1 - Insert 2 - Delete 3 - List 4 - Close Please Enter The Option
PDF
No ratings yet
MENU 1 - Insert 2 - Delete 3 - List 4 - Close Please Enter The Option
10 pages
Pg 9 node
PDF
No ratings yet
Pg 9 node
5 pages
A039 - Exp - 5 Implementation of Doubly Linked List
PDF
No ratings yet
A039 - Exp - 5 Implementation of Doubly Linked List
15 pages
11 Week Dsa Workshop by Geeksforgeeks: Instructor: Rahul Singla
PDF
No ratings yet
11 Week Dsa Workshop by Geeksforgeeks: Instructor: Rahul Singla
37 pages
Stack Using Linked List
PDF
No ratings yet
Stack Using Linked List
20 pages
Write A Java Program For Performing Various Operations On Queue Using Linked List
PDF
No ratings yet
Write A Java Program For Performing Various Operations On Queue Using Linked List
20 pages
Java Data Structure
PDF
No ratings yet
Java Data Structure
14 pages
Java Lap Manual
PDF
No ratings yet
Java Lap Manual
37 pages
Program For Implementing A Stack & To Perform Push & Pop Operations
PDF
No ratings yet
Program For Implementing A Stack & To Perform Push & Pop Operations
28 pages
Singly Linked List
PDF
No ratings yet
Singly Linked List
18 pages
Linked List
PDF
No ratings yet
Linked List
22 pages
Ds
PDF
No ratings yet
Ds
8 pages
Lecture 23
PDF
No ratings yet
Lecture 23
4 pages
Lab 7
PDF
No ratings yet
Lab 7
12 pages
Recursion, Linked List Queue & Deque
PDF
No ratings yet
Recursion, Linked List Queue & Deque
24 pages
Dsa Programs
PDF
No ratings yet
Dsa Programs
5 pages
Answer The Question Which Carries Five Marks
PDF
No ratings yet
Answer The Question Which Carries Five Marks
11 pages
bscs-140 SYED ALI RAZA ZAIDI
PDF
No ratings yet
bscs-140 SYED ALI RAZA ZAIDI
18 pages
adsaaaa
PDF
No ratings yet
adsaaaa
28 pages
Dsa Lab File
PDF
No ratings yet
Dsa Lab File
11 pages
LAB NO 2 DSA
PDF
No ratings yet
LAB NO 2 DSA
23 pages
Program-21: To Implement A Stack and Manage Data
PDF
No ratings yet
Program-21: To Implement A Stack and Manage Data
16 pages
DSA M1&2 QB answers
PDF
No ratings yet
DSA M1&2 QB answers
25 pages
Remove An Element From Linked List
PDF
No ratings yet
Remove An Element From Linked List
8 pages
DS Using Java on Novb 10 (1)
PDF
No ratings yet
DS Using Java on Novb 10 (1)
90 pages
SDOT Training Codes
PDF
No ratings yet
SDOT Training Codes
29 pages
Java Lab Programs
PDF
No ratings yet
Java Lab Programs
53 pages
Record and Observation
PDF
No ratings yet
Record and Observation
23 pages
Oop Set 8
PDF
No ratings yet
Oop Set 8
7 pages
Add On
PDF
No ratings yet
Add On
8 pages
Java Assignment
PDF
No ratings yet
Java Assignment
15 pages
Daa 1.4
PDF
No ratings yet
Daa 1.4
22 pages
Java Program For Set Intersection
PDF
No ratings yet
Java Program For Set Intersection
5 pages
ADSA Lab
PDF
No ratings yet
ADSA Lab
30 pages
Theory Assgnment2
PDF
No ratings yet
Theory Assgnment2
6 pages
DSA Assignment - 3
PDF
No ratings yet
DSA Assignment - 3
9 pages
LABSHEET 3,4
PDF
No ratings yet
LABSHEET 3,4
18 pages
31-35
PDF
No ratings yet
31-35
20 pages
Queue Code
PDF
No ratings yet
Queue Code
1 page
Linked List in data structure and algorithm
PDF
No ratings yet
Linked List in data structure and algorithm
8 pages
Nimsabda
PDF
No ratings yet
Nimsabda
36 pages
JAVA - Slips 1-15
PDF
67% (3)
JAVA - Slips 1-15
67 pages
Data Structure Lab 9
PDF
No ratings yet
Data Structure Lab 9
6 pages
Queue Assignment
PDF
No ratings yet
Queue Assignment
25 pages
Java Lab Internal1 Q&A
PDF
No ratings yet
Java Lab Internal1 Q&A
19 pages
Sec3 Program
PDF
No ratings yet
Sec3 Program
41 pages
21BCE9726 - DSA Lab - FINAL REPORT
PDF
No ratings yet
21BCE9726 - DSA Lab - FINAL REPORT
50 pages
Circularlinkedlist
PDF
No ratings yet
Circularlinkedlist
10 pages
LAB 1: Programming in C To Analyse The Complexity of Different Programs
PDF
No ratings yet
LAB 1: Programming in C To Analyse The Complexity of Different Programs
28 pages
Dsa File-3-56
PDF
No ratings yet
Dsa File-3-56
54 pages
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
Data Structures Using Java - Lab Manual
PDF
Data Structures Using Java - Lab Manual
algorithm-1
PDF
algorithm-1
Stack Using Arrays
PDF
Stack Using Arrays
Csit 365
PDF
Csit 365
2379
PDF
2379
DSA File
PDF
DSA File
Bda
PDF
Bda
Hadoop Lab Manual
PDF
Hadoop Lab Manual
Unit1 Hadoop
PDF
Unit1 Hadoop
MENU 1 - Insert 2 - Delete 3 - List 4 - Close Please Enter The Option
PDF
MENU 1 - Insert 2 - Delete 3 - List 4 - Close Please Enter The Option
Pg 9 node
PDF
Pg 9 node
A039 - Exp - 5 Implementation of Doubly Linked List
PDF
A039 - Exp - 5 Implementation of Doubly Linked List
11 Week Dsa Workshop by Geeksforgeeks: Instructor: Rahul Singla
PDF
11 Week Dsa Workshop by Geeksforgeeks: Instructor: Rahul Singla
Stack Using Linked List
PDF
Stack Using Linked List
Write A Java Program For Performing Various Operations On Queue Using Linked List
PDF
Write A Java Program For Performing Various Operations On Queue Using Linked List
Java Data Structure
PDF
Java Data Structure
Java Lap Manual
PDF
Java Lap Manual
Program For Implementing A Stack & To Perform Push & Pop Operations
PDF
Program For Implementing A Stack & To Perform Push & Pop Operations
Singly Linked List
PDF
Singly Linked List
Linked List
PDF
Linked List
Ds
PDF
Ds
Lecture 23
PDF
Lecture 23
Lab 7
PDF
Lab 7
Recursion, Linked List Queue & Deque
PDF
Recursion, Linked List Queue & Deque
Dsa Programs
PDF
Dsa Programs
Answer The Question Which Carries Five Marks
PDF
Answer The Question Which Carries Five Marks
bscs-140 SYED ALI RAZA ZAIDI
PDF
bscs-140 SYED ALI RAZA ZAIDI
adsaaaa
PDF
adsaaaa
Dsa Lab File
PDF
Dsa Lab File
LAB NO 2 DSA
PDF
LAB NO 2 DSA
Program-21: To Implement A Stack and Manage Data
PDF
Program-21: To Implement A Stack and Manage Data
DSA M1&2 QB answers
PDF
DSA M1&2 QB answers
Remove An Element From Linked List
PDF
Remove An Element From Linked List
DS Using Java on Novb 10 (1)
PDF
DS Using Java on Novb 10 (1)
SDOT Training Codes
PDF
SDOT Training Codes
Java Lab Programs
PDF
Java Lab Programs
Record and Observation
PDF
Record and Observation
Oop Set 8
PDF
Oop Set 8
Add On
PDF
Add On
Java Assignment
PDF
Java Assignment
Daa 1.4
PDF
Daa 1.4
Java Program For Set Intersection
PDF
Java Program For Set Intersection
ADSA Lab
PDF
ADSA Lab
Theory Assgnment2
PDF
Theory Assgnment2
DSA Assignment - 3
PDF
DSA Assignment - 3
LABSHEET 3,4
PDF
LABSHEET 3,4
31-35
PDF
31-35
Queue Code
PDF
Queue Code
Linked List in data structure and algorithm
PDF
Linked List in data structure and algorithm
Nimsabda
PDF
Nimsabda
JAVA - Slips 1-15
PDF
JAVA - Slips 1-15
Data Structure Lab 9
PDF
Data Structure Lab 9
Queue Assignment
PDF
Queue Assignment
Java Lab Internal1 Q&A
PDF
Java Lab Internal1 Q&A
Sec3 Program
PDF
Sec3 Program
21BCE9726 - DSA Lab - FINAL REPORT
PDF
21BCE9726 - DSA Lab - FINAL REPORT
Circularlinkedlist
PDF
Circularlinkedlist
LAB 1: Programming in C To Analyse The Complexity of Different Programs
PDF
LAB 1: Programming in C To Analyse The Complexity of Different Programs
Dsa File-3-56
PDF
Dsa File-3-56