Skip to content

Commit

Permalink
create front and back functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasbivar committed Apr 12, 2021
1 parent 1971e34 commit 45e5341
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
37 changes: 36 additions & 1 deletion DynamicQueue/dynamicQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,39 @@ int pop(dynamicQueue* q){
free(aux);
q->size--;
return 1;
}
}

int front(dynamicQueue* q, struct student* student){
if(q == NULL) return 0;
if(empty(q)) return 0;

*student = q->begin->data;

return 1;
}

int back(dynamicQueue* q, struct student* student){
if(q == NULL) return 0;
if(empty(q)) return 0;

*student = q->end->data;

return 1;
}

int show(dynamicQueue* q){
if(q == NULL) return 0;
if(empty(q)) return 0;

Node* current = q->begin;
printf("\n=-=-=-=-=-=-=-=-=-Queue of Students-=-=-=-=-=-=-=-=-=\n");
while(current != NULL){
printf("Name: %s", current->data.name);
printf("Enrollment: %d\n", current->data.enrollment);
printf("Pontuation 1: %.2f\n", current->data.p1);
printf("Pontuation 2: %.2f\n", current->data.p2);
printf("Pontuation 3: %.2f\n\n", current->data.p3);
current = current->next;
}
return 1;
}
8 changes: 7 additions & 1 deletion DynamicQueue/dynamicQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ int full(dynamicQueue* q);

int push(dynamicQueue* q, struct student student);

int pop(dynamicQueue* q);
int pop(dynamicQueue* q);

int front(dynamicQueue* q, struct student* student);

int back(dynamicQueue* q, struct student* student);

int show(dynamicQueue* q);

0 comments on commit 45e5341

Please sign in to comment.