Data Structure Lab 3
Data Structure Lab 3
return remainder(a-b,b);
}
}
---------------------------------------------------
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Difference: " + MyMath.difference(5, 3));
System.out.println("Addition: " + MyMath.addition(5, 3));
System.out.println("Multiplication: " + MyMath.multiplication(5, 3));
System.out.println("Factorial: " + MyMath.factorial(5));
System.out.println("Power: " + MyMath.power(2, 3));
System.out.println("Quotient: " + MyMath.quotient(10, 3));
System.out.println("Is Prime: " + MyMath.prime(7));
System.out.println("Remainder: " + MyMath.remainder(10, 3));
}
-----------------------------------------
EX2:
}
a[0]=value;
currentNb++;
return true;
} else {
System.out.println("Error: Array is full.");
return false;
}
}
public boolean InsertAtPosition(int position, int value) {
if (!isFull() && position >= 0 && position <= currentNb) {
for (int i = currentNb; i > position; i--) {
a[i] = a[i - 1];
}
a[position] = value;
currentNb++;
return true;
} else {
System.out.println("Error: Invalid position or array is full.");
return false;
}
}
public void Display() {
for (int i = 0; i < currentNb; i++) {
System.out.print(a[i] + " ");
}
System.out.println();
}
if (minIndex != i) {
int temp = a[i];
a[i] = a[minIndex];
a[minIndex] = temp;
}
}
}
public void DeleteMultiplesOfThree() {
int newSize = currentNb;
for (int i = 0; i < newSize; i++) {
if (a[i] % 3 == 0) {
for (int j = i; j < newSize - 1; j++) {
a[j] = a[j + 1];
}
newSize--;
i--;
}
}
currentNb = newSize;
}
if (a[pos] == value) {
return true;
}
if (a[mid] < x) {
return IntervalBinarySearch(mid + 1, r, x);
}
return false;
}
-------------------------------------------
-----------------------------------------
EX3:
---------------------------------------------
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("please enter the number of discs");
int numberOfDisks=sc.nextInt();
TowerOfHanoi.towerOfHanoi(numberOfDisks, 'A', 'B', 'C');
}