Answered You can hire a professional tutor to get the answer.

QUESTION

I am having issues implementing a Queue data structures and some functions. A queue consists of a head-pointer and a set of q-elements.

I am having issues implementing a Queue data structures and some functions. I have attached a description below

Data Structures:

A queue consists of a head-pointer and a set of q-elements.

A q-element is a structure, consisting of a prev and next pointer, and a payload consisting of 1 integer.

The header is a pointer to the first element of the queue. The head pointer is "null" if the q is empty.

The functions i need help with:

1. item = NewItem(); // returns a pointer to a new q-element

2. tnitQueue( &head) // creates a empty queue, pointed to by the variable head.

3. addQueue(&head, item) // adds a queue item, pointed to by "item", to the queue pointed to by head.

4. item = DelQueue(&head) // deletes an item from head and returns a pointer to the deleted item

5. rotateQ(&head) // Moves the header pointer to the next element in the queue. This is equivalent to AddQ(&head, DeleteQ(&head)), but is simpler to use and more efficient to implement.

6. freeItem()

Note: All the routines work on pointers. They do not copy q-elements. Also they to not allocate/deallocate space (except NewItem()).

.

It would help if you could write comments for the function so i can easily walk through a better understand what is going on. thank in advance

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question