Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:aaca51fb4854, committed 2018-07-28
- Comitter:
- alejo5214416
- Date:
- Sat Jul 28 01:29:39 2018 +0000
- Commit message:
- Comunicacion maestro esclavo con confirmacion de 1S 1Y 1N para solicitudes y respuestas
Changed in this revision
| qnode.cpp | Show annotated file Show diff for this revision Revisions of this file |
| qnode.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qnode.cpp Sat Jul 28 01:29:39 2018 +0000
@@ -0,0 +1,59 @@
+#include "qnode.h"
+#include "mbed.h"
+
+
+// A utility function to create a new linked list node.
+QNode* newNode(uint8_t *k)
+{
+ QNode *temp = (struct QNode*)malloc(sizeof(struct QNode));
+ for(int i=0;i<4;i++){
+ temp->uid[i]=k[i];
+ }
+ temp->next= NULL;
+ return temp;
+}
+
+// A utility function to create an empty queue
+struct Queue *createQueue()
+{
+ struct Queue *q = (struct Queue*)malloc(sizeof(struct Queue));
+ q->front = q->rear = NULL;
+ return q;
+}
+
+// The function to add a key k to q
+void enQueue(struct Queue *q, uint8_t *k)
+{
+ // Create a new LL node
+ struct QNode *temp = newNode(k);
+
+ // If queue is empty, then new node is front and rear both
+ if (q->rear == NULL)
+ {
+ q->front = q->rear = temp;
+ return;
+ }
+
+ // Add the new node at the end of queue and change rear
+ q->rear->next = temp;
+ q->rear = temp;
+}
+
+// Function to remove a key from given queue q
+struct QNode *deQueue(struct Queue *q)
+{
+ // If queue is empty, return NULL.
+ if (q->front == NULL)
+ return NULL;
+
+ // Store previous front and move front one node ahead
+ struct QNode *temp = q->front;
+ q->front = q->front->next;
+
+ // If front becomes NULL, then change rear also as NULL
+ if (q->front == NULL)
+ q->rear = NULL;
+ return temp;
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/qnode.h Sat Jul 28 01:29:39 2018 +0000
@@ -0,0 +1,25 @@
+#include "mbed.h"
+
+#ifndef QNODE_H
+#define QNODE_H
+
+typedef struct QNode{
+ uint8_t uid[4];
+ struct QNode *next;
+} QNode;
+
+// The queue, front stores the front node of LL and rear stores ths
+// last node of LL
+struct Queue
+{
+ struct QNode *front, *rear;
+};
+
+
+struct QNode* newNode(uint8_t* k);
+struct Queue *createQueue();
+void enQueue(struct Queue *q, uint8_t *k);
+struct QNode *deQueue(struct Queue *q);
+
+
+#endif
\ No newline at end of file