The Stack Data Structure follows the principle of Last In First Out which means the last element inserted is the one to be taken out first.
Real world example would be a stack of CDs. To take out the bottom one you will have to remove the CDs on top of it. And in this Data Structure you have to remove each element one by one.
This example is implemented using an array, hence contains elements of the same data type only.
A Stack comes in handy when you need to reverse a character array and this will show you how.
STEP 1:
The Stack class should be implemented as below.
STEP 2:
The GUI should be designed as preferred. Then, the Stack is created dynamically in case it needs to be accessed in different events and for the button click the below code should be added.
STEP 3:
An object of the JFrame Class (GUI) should be created in the main program and the visibility should be set to true.
Now, you can run the program and use it to reverse any string.
Real world example would be a stack of CDs. To take out the bottom one you will have to remove the CDs on top of it. And in this Data Structure you have to remove each element one by one.
This example is implemented using an array, hence contains elements of the same data type only.
A Stack comes in handy when you need to reverse a character array and this will show you how.
STEP 1:
The Stack class should be implemented as below.
STEP 2:
The GUI should be designed as preferred. Then, the Stack is created dynamically in case it needs to be accessed in different events and for the button click the below code should be added.
STEP 3:
An object of the JFrame Class (GUI) should be created in the main program and the visibility should be set to true.
Now, you can run the program and use it to reverse any string.
Very informative and impressive post you have written, this is quite interesting and i have went through it completely, an upgraded information is shared, keep sharing such valuable information .
ReplyDeleteget more: Data Structures Using Java