pointer1.c
#include <stdio.h>
#include <stdlib.h>
struct Node {
float x, y, z;
struct Node *next;
};
int Qsize = 0;
typedef struct Node Node;
Node *front;
Node *rear;
Node* newNode(float a, float b, float c) {
Node* ptr = (Node*)malloc(1*sizeof(Node));
ptr->x = a;
ptr->y = b;
ptr->z = c;
ptr->next = 0;
return ptr;
}
void addQ(float a, float b, float c) {
Qsize++;
Node *ptr = newNode(a, b, c);
Node *tmp = rear;
if (Qsize == 1) {
front = ptr;
rear = front;
}
else {
rear = ptr;
tmp->next = ptr;
}
}
Node * getNode(){
Node *tmp = front;
if (Qsize == 1) {
front = 0;
} else {
front = tmp->next ;
}
Qsize--;
return tmp;
}
int main() {
addQ( 1, 1, 1);
addQ( 2, 1, 1);
addQ( 3, 1, 1);
addQ( 4, 1, 1);
free(getNode());
free(getNode());
free(getNode());
printf("%d %f %f\n", Qsize, front->x, rear->x);
}