Just wondering if you would help me in my assignment, I've started on them.
I've done most of it except the following three questions.

(1) Any flight can be brought to the front of the queue ready for deleting (landing)
For example if the flight is in the back, we can bring it in the front


(3) In the flight ID, there can only be one unique letter, for example A, a, B, b, we cannot have A, A, but we can have A, a

Please help me, if you find it a little hard, just do what you can, or which one you can.

Thanks

Code removed at OP's request

Code tags added. -Narue

>the following three questions
You only have two questions.

>Any flight can be brought to the front of the queue ready for deleting
Since your queue is implemented with a linked list, you can easily splice out an item and replace it elsewhere:

void moveToFront ( queue& q, const char data )
{
  nodePtr item;

  // Check to see if it's already at the front
  if ( data == q.front->data )
    return;

  // Find the item
  for ( nodePtr it = q.front; it->next != 0; it = it->next ) {
    if ( data == it->next->data ) {
      item = it->next;
      it->next = item->next;
      break;
    }
  }

  // Move to front
  item->next = q.front;
  q.front = item;
}

>In the flight ID, there can only be one unique letter
For each new ID, traverse the queue and make sure it doesn't already exist:

bool isUnique ( queue& q, const char data )
{
  for ( nodePtr it = q.front; it != 0; it = it->next ) {
    if ( data == it->data )
      return false;
  }

  return true;
}

please ignore this

it can only move it once, can someone help

>it can only move it once
Once an item is moved, it's already at the front and moving it again will have no effect. Call moveToFront with a different (existing!) item.

what does -> mean, when you wrote temp->data = item; ?

I never seen queue& i got it from when you wrote, void moveToFront ( queue& q, const char data ). What does it mean?

what does -> mean, when you wrote temp->data = item; ?

It is used to access a member of a class/struct/union from a pointer rather than from the object itself -- which uses the . operator.

#include <stdio.h>

struct type
{
   int member;
};

int main(void)
{
   struct type object = {42};
   struct type *ptr = &object;
   printf("object.member = %d\n", object.member);
   printf("ptr->member   = %d\n", ptr->member);
   return 0;
}

/* my output
object.member = 42
ptr->member   = 42
*/

I never seen queue& i got it from when you wrote, void moveToFront ( queue& q, const char data ). What does it mean?

The & is used to declare a reference.

>I never seen queue& i got it from when you wrote
I thought you knew what references were because the code you posted originally used them:

void addToQueue(queue&, char);
void deleteFromQueue(queue&, char&);

^^^

yeah, i'm better at references now but i'm only familiar with & used before an object like when dave wrote:

struct type *ptr = &object;

mel2005 (who I think is my brother) used it after and it looks like the data type for a parameter of a function by looking at the signature.

I guess you can put the & before or after the object when calling by reference. This is hard *scratches head* lol

>i'm only familiar with & used before an object
That's a pointer. ;) More precisely, it's the address-of operator that returns a pointer to the address of the object you use as its operand.

It is used to access a member of a class/struct/union from a pointer rather than from the object itself -- which uses the . operator.

#include <stdio.h>

struct type
{
   int member;
};

int main(void)
{
   struct type object = {42};
   struct type *ptr = &object;
   printf("object.member = %d\n", object.member);
   printf("ptr->member   = %d\n", ptr->member);
   return 0;
}

/* my output
object.member = 42
ptr->member   = 42
*/

The & is used to declare a reference.

Okay Dave, I just got through reading a little bit about Structures to understand your example. I think I got it thank you. I just learnt Structs, kinda sorta ;)

let me point this out since I know a little more about structs how, my book says you could of wrote:

printf("(*ptr).member = %d\n", ptr->member);

and you would of got the samething right???

Thanx!

>i'm only familiar with & used before an object
That's a pointer. ;) More precisely, it's the address-of operator that returns a pointer to the address of the object you use as its operand.

gotcha, i hope :o

and you would of got the samething right???

Yes.

#include <stdio.h>

struct type
{
   int member;
};

int main(void)
{
   struct type object = {42};
   struct type *ptr = &object;
   printf("object.member = %d\n", object.member);
   printf("ptr->member   = %d\n", ptr->member);
   printf("(*ptr).member = %d\n", (*ptr).member);
   return 0;
}

/* my output
object.member = 42
ptr->member   = 42
(*ptr).member = 42
*/

This is because *ptr is an object and not a pointer. The parentheses are necessary because of "operator precedence".

^^^

That's right! How do you know all this?

Havery and Paul Deitel wrote my "C++ How to Program" book, not Dave Sinkula

lol

:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.