Stack Implementation using two arrays in Java || Stack Implementation

preview_player
Показать описание
#learnwithkrishnasandeep #javacodinginterviewquestions #javaexamples #javaprograms #javatutorials #javaprogramming Stack Implementation using two arrays in Java

Java Program to check whether two Strings are anagrams or not

(For all updates on Java interview questions and java tutorials join the telegram group)
Search in Telegram with text Java Tutorials if you are unable to join telegram with above link

1) How to read a matrix from console in java?

2) How to remove duplicates from string in java?

3) Write a java program to duplicate characters with number of occurences in java?

4) Write a java program to implement bubble sort part 1?

5) Write a java program to check string is palindrome or not?

6) Write a java program to print floyds triangle?

7) Write a java program to print floyds triangle?





8) How to count number of vowels in a string in java?

9) How to find largest and smallest values in an array in java?

10) Write java program to find duplicate elements in array in java?

11) write a java program to check the input number is prime or not in java?

12) Write a java program to print pyramid pattern of numbers?

13) Write a java program to find missing number in array in java?

14)Write a java program to print numbers in java up to 10 with out using loops?

15) How to sort elements in array in asc and desc order in java?



16) Write a java program to find factorial of a number in java?

17) write a java program to find second largest element in the array in the java?

18) Write a java program to check two Strings are anagrams or not by sorting and comparing strings?

19) Write java program to print Characters count in each word in String ?

20) Write a java program to find reverse of a string in java?

21) Write a java program to add elements in an array in java?

22) Write a java program to find largest of three numbers?



23) Write a java program to print multiplication table?

24) Write a java program to print star pattern?

25) Write a java program to find factors of number from 1 to 100

26) Write a java program to print fibonacci series using loops?

27) Write a java program to print Ascii values of a Character ?

28) write a java program to implement bubble sort - Part 2?

29) Write a java program to print fibonacci series ?

30) Write a java program to sort characters in String in java?

31) How to sort hashmap keys in java?

32) Write a java program to check two strings are anagrams or not?

33) Write a java program to find factorial for large number?

34) Write a java program to find even and odd number?

35) How to Swap two numbers without using third variable in java?(Addition and subtraction operation)

36) Write a java program to convert Fahrenheit to celsius?

37) Write a java program to find reverse of a number in java?

38) Write a java program to print alphabets?

39) Write a java program to check given input character is alphabet or not ?

40) How to reverse the order of elements in arraylist in java?

41) How to swap elements in list in java?

42) Write a java program to find sum of 10 numbers in java?

43) How to swap two numbers in java?

44) How to swap two numbers in java with out using temp variable?

45) Write a java program to check whether array contains duplicates?

46) How to calculate area of Rectangle in java?

Рекомендации по теме
Комментарии
Автор

Great thank you, actually in the method pop2() when we display the element then top2 should be top2++ rather than top2-- right

mooht
Автор

why first if condition is not if(top1<top2-1)
it may fail for some condtions(if top1 pointing to 2 index and top2 pointing to 3 index positions of array)

eashwarreddy
Автор

Please review and let me know :)

import java.util.Arrays;

public class TwoStacks {
int size;
int top1;
int top2;
int arr[];

public TwoStacks(int size) {
this.size = size;
this.arr = new int[size];
top1 = -1;
top2 = size;
}

public void push1(int value) {
top1++;
if (top1 == top2) {
System.out.println("Not enough memory in stack1");
top1--;
return; // should show error message
}

arr[top1] = value;
size++;
}

public void push2(int value) {
top2--;
if (top2 == top1) {
System.out.println("Not enough memory in stack2");
top2++;
return;
}

arr[top2] = value;
size++;
}

public int pop1() {
if (top1 == -1) {
System.out.println("Stack1 is empty");
return 0;
}

int value = arr[top1];
arr[top1] = 0;
top1--;
size--;

return value;
}

public int pop2() {
if (top2 == arr.length) {
System.out.println("Stack2 is empty");
return 0;
}

int value = arr[top2];
arr[top2] = 0;
top2++;
size--;

return value;
}

public void printArray() {

}
}

Manikandan-nnbw
Автор

Sir if the array consist of odd space consistent like 0 to 4... then we divide the array into two equal stacks right???

sweetsisters
Автор

return 0 in the functions is unreachable, isnt it? after system.exit(1), the control will not be with the function anymore.

onkarkulkarni