![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: algorithm, analysis, help, programming, queue, stack, tutorial |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| ||||
| Hello everybody, back again to HelloWorld's tutorial on Java ![]() In this tutorial, we basically going to analyze Stack and Queue's algorithms that's going to be implemented differently using both Vectors and Arrays. As we learned before in Tutorial: Simple Algorithm Analysis ArrayList and Vector are actually types of Data Structure that uses the fundamental Arrays. Then you probably may be able to guess what's the underline Data Structure for Stacks and Queues too!!! Guess what, Stack and Queues are actually use VECTOR as their underline data structure!!! Why Vector not ArrayList?? The answer is I don't know, and should probably ask Sun for that ![]() In this tutorial, we're going to analyze different run-time when we implement our Stack and Queues using Vector, and Arrays. How long does it take time to POP, PEEK, and PUSH? How long does it take to ENQUEUE and DEQUEUE? as well as the SORTED version too ![]() P.S we're going to create our own version of Stacks and Queues. If you don't know about this, below is a little intro: Stacks and Queues are actually just other type of Data Structures that we have in Java. Here are the difference between them: Stacks You're washing dishes and have 10 plates (doesn't have to be 10, whatever number you have for your plates) and you stack them together once you're done washing them. IF you are going to use the plate, then of course you're not going to bother to get it from the bottom, so you will get the plate that's on the top. So is the same with Stacks, and in Computer Science, we call Stacks as LIFO (Last In First Out) Data Structure Queues You're about to watch movie, I hope that you don't cut the people in front of you because they will get mad!!! So, you have to wait in line (it's called queue in UK if I'm not wrong) if you get to be the first person in line, you will be the first one that gets the ticket and get out of the line. So, it is the same with Queues, and in Computer Science, we call Queues as FIFO (First In First Out) Data Structure Hopefully that little introduction gives you some little more background about Stacks and Queues. I see that those two stories work best for me to understand Stacks and Queues, so that's the best that I can come up with. However, feel free to add and ask questions. Also, hope that my code below is self explanatory. It's really, straight forward. You can see the way I implement different things there using Arrays and Vector. I believe that programmers are reading codes better than bunch of paragraphs ![]() Stack.java - ARRAYS IMPLEMENTATION PHP Code: PHP Code: PHP Code: PHP Code: (Sorry, this is only for Integers) PHP Code: (This one also only for Integers) PHP Code: |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |