HOME BZU Mail Box Online Games Radio and TV Live Cricket Score All Albums
Go Back   BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan Institute of Computing Bachelor of Science in Telecom System BsTS 2nd Semester

Advertisement Banner
Reply
 
Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1  
Old 26-02-2011, 11:51 PM
bonfire's Avatar
M.Arsalan Qureshi

 

Join Date: Oct 2008
Location: Garden Town, Multan Cantt
Posts: 630
Thanks: 238
Thanked 238 Times in 147 Posts
Program / Discipline: BSTS
Class Roll Number: 09-31
bonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond reputebonfire has a reputation beyond repute
Time Spent Online: 4 Days 15 Hours 26 Minutes 57 Seconds
Default Queue in Data Structures


The Queue Data Structure - Eric Suh

Queues are data structures that, like the stack, have restrictions on where you can add and remove elements. To understand a queue, think of a cafeteria line: the person at the front is served first, and people are added to the line at the back. Thus, the first person in line is served first, and the last person is served last. This can be abbreviated to First In, First Out (FIFO).


The cafeteria line is one type of queue. Queues are often used in programming networks, operating systems, and other situations in which many different processes must share resources such as CPU time.
One bit of terminology: the addition of an element to a queue is known as an enqueue, and removing an element from the queue is known as a dequeue.
Although the concept may be simple, programming a queue is not as simple as programming a stack. Let's go back to the example of the cafeteria line. Let's say one person leaves the line. Then what? Everyone in line must step forward, right? Now, imagine if only one person could move at a time. So, the second person steps forward to fill the space left by the first person, and then the third person steps forwards to fill the space left by the second person, and so on. Now imagine that no one can leave or be added to the line until everyone has stepped forward. You can see the line will move very slowly. It is not difficult to program a queue that works, but it is quite a proposition to make a queue that is fast!!
There are a couple of basic ways to implement a queue. The first is to just make an array and shift all the elements to accommodate enqueues and dequeues. This, as we said above, is slow.
The slowness of the previous method is that with many elements, the shifting takes time. Thus, another method, instead of shifting the elements, shifts the enqueue and dequeue points. Imagine that cafeteria line again. If the front of the line continually moves backwards as each person leaves the line, then the people don't need to step forward or backwards, which saves time.
Unfortunately, this method is much more complicated than the basic method. Instead of keeping track of just the enqueue point (the "end"), we also need to keep track of the dequeue point (the "front"). This all gets even more complicated when we realize that after a bunch of enqueues and dequeues, the line will need to wrap around the end of the array. Think of the cafeteria line. As people enter and leave the line, the line moves farther and farther backwards, and eventually it will circle the entire cafeteria and end up at its original location.
The best way to understand all of this is to read some source code. The example source code uses the second method, and is commented to help you understand. Try working through the code on paper.


Download attachment bellow:-
Attached Files
File Type: docx Queue in Data Structure (www.bzupages.com).docx (12.4 KB, 55 views)
__________________

Reply With Quote
Top 10 Lists | Live Cricket Score

Reply

Tags
data, queue, structures


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trees in Data Structures bonfire BsTS 2nd Semester 1 04-12-2011 11:29 PM
Concept of Graph in Data Structures. bonfire BsTS 2nd Semester 0 26-02-2011 11:55 PM
Heap in Data Structures bonfire BsTS 2nd Semester 0 26-02-2011 11:52 PM
Stacks in Data Structures bonfire BsTS 2nd Semester 0 26-02-2011 11:50 PM
[PPT] Chapter 2. Data Warehouse and OLAP Technology for Data Mini - Data Mining Concepts and Techniques Han and Kamber BSIT07-01 Dataware Housing & data mining 0 03-11-2010 03:10 AM

Best view in Firefox
Free File Hosting | Webmaster Forum | Cloud Computing | Dedicated server hosting
Note: All trademarks and copyrights held by respective owners. We will take action against any copyright violation if it is proved to us.

All times are GMT +5. The time now is 06:45 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.