In C + +, when a variable int a is defined; when int &b=a; When defined with the address operator, it means: use B as an alias, give B memory space to store A's address space can almost be used as a pointer
In this example, in the function parameter pass, the alias is used to change the value of the argument using this form in the called function.
Here in the main function of local variables, local variables are stored in the form of the stack, the local variable into the stack, it will only the end of the main function will release the local variable inside
Save, when you enter the custom function, although PUSHSP, but the value of the stack register SP does not change, so you can directly as B as a alias, directly through the stack access to the memory space of a
BOOL Boolean type occupies only 1 bytes, #definefalse 0 #define TRUE 0 in header file
#include #include #include typedef int queue_element;
typedef struct QUEUENODE {queue_element num;
Queuenode *next;
}*node;
struct Linkqueue {node ele_rear, ele_front;}; BOOL Initqueue (Linkqueue &queue)//construct an empty queue {//To assign space to queue header and tail if (!) (
Queue.ele_front = Queue.ele_rear = (node) malloc (sizeof (Queuenode)))//Decide whether to assign success {printf ("Memory error!\n");
return false;
printf ("Memory right!\n");
Queue.ele_front->next = NULL;
return true;
} void Add (Linkqueue &queue,queue_element value)//inserts {node P = (node) malloc (sizeof (Queuenode)) from the tail of the queue;
P->num = value;
P->next = NULL;
Queue.ele_rear->next = p;
Queue.ele_rear = p; BOOL Remove (Linkqueue &queue) {node p;
The first if (Queue.ele_front = queue.ele_rear) {printf ("Memory error!\n") of the receiving queue is placed in the middle structure.
return false; } p = queue.ele_front->next;
Point P to the header of the queue Queue.ele_front->next = p->next;
if (p = = queue.ele_rear) Queue.ele_rear = Queue.ele_front; Freep);
return true;
int Getfront (linkqueue queue)//Get queue first {int _value;
if (Queue.ele_front = = queue.ele_rear)//Determine whether the queue is empty {printf ("The queue have no element");
return 0;
} _value = queue.ele_front->next->num;
return _value;
} void Traverse (Linkqueue queue) {node p;
p = queue.ele_front->next;
printf ("The values of the queue is:");
while (P!= queue.ele_rear->next) {printf ("%d", p->num);
p = p->next;
} void Destroy (Linkqueue &queue) {while (Queue.ele_front) {queue.ele_rear = queue.ele_front->next;
Free (Queue.ele_front);
Queue.ele_front = Queue.ele_rear;
int main () {Linkqueue queue;
int i;
int value[8] = {1,2,3,4,5,6,7,8}; Initqueue (queue);
Empty queue for (i=0;i<8;i++) Add (queue, value[i]);
int _value;
_value = Getfront (queue);
if (_value!=0) printf ("The head value is%d\n", _value);
Remove (queue); Traverse (queue);
Traversal by the queue header to the queue tail destroy (queue); printf ("\nthe queue rear element is%d,the queueFront element is%d ", queue.ele_rear, Queue.ele_front);
System ("pause");