{"id":474,"date":"2012-11-26T18:39:47","date_gmt":"2012-11-26T11:39:47","guid":{"rendered":"http:\/\/blog.kusumoto.co\/?p=474"},"modified":"2012-11-26T18:39:47","modified_gmt":"2012-11-26T11:39:47","slug":"lab_capture-4-queue","status":"publish","type":"post","link":"https:\/\/oldblog.kusumotolab.com\/?p=474","title":{"rendered":"Lab_Capture-4 :: Queue"},"content":{"rendered":"<p><a href=\"http:\/\/img.kusumoto.co\/show\/594\" target=\"_blank\"><img decoding=\"async\" src=\"http:\/\/img.kusumoto.co\/i\/BZA.png\" alt=\"Host by img.kusumoto.co\" \/><\/a><\/p>\n<pre lang=\"c\">\r\n#include <stdio.h>\r\ntypedef struct head {\r\n\tstruct node *front;\r\n\tint count;\r\n\tstruct node *rear;\r\n}HEAD;\r\n\r\ntypedef struct node {\r\n\tint data;\r\n\tstruct node *next;\r\n}NODE;\r\n\/\/start PrintQueue\r\nvoid PrintQueue(HEAD *headNode) {\r\n\tNODE *printNode=headNode->front;\r\n\tint numberOfQueue = headNode->count;\r\n\tint tempData[numberOfQueue];\r\n\t\r\n\tprintf(\"\\n----------Print Queue-----------\\n\");\r\n\twhile(printNode!=NULL) {\r\n\t\t\/\/get data into array for display\r\n\t\ttempData[numberOfQueue-1] = printNode->data;\r\n\t\tprintNode = printNode->next;\r\n\t\tnumberOfQueue--;\r\n\t}\r\n\tint i;\r\n\tfor(i=0;i<headNode->count;i++) {\r\n\t\tprintf(\" | %d | \\n\",tempData[i]);\r\n\t      }\r\n\t   printf(\"-----------------------------\\n\");\r\n\t}\r\n\r\n\/\/end PrintQueue\r\n\/\/start Enqueue\r\nvoid Enqueue(HEAD *headNode,int data) {\r\n\t\/\/create new node\r\n\tNODE *newNode;\r\n\tnewNode = (NODE*)malloc(sizeof(NODE));\r\n\t\/\/set data\r\n\tnewNode->data = data;\r\n\t\/\/set link new node to NULL\r\n\tnewNode->next = NULL;\r\n\t\/\/link rear node ,to new node\r\n\tif(headNode->rear==NULL) {\r\n\t\t\/\/in case first node\r\n\t\theadNode->front = newNode;\r\n\t\theadNode->rear = newNode;\r\n\t}else{\r\n\t\t\theadNode->rear->next = newNode;\r\n\t}\r\n\t\/\/set new node is rear\r\n\theadNode->rear = newNode;\r\n\t\/\/increase count\r\n\theadNode->count++;\r\n\t\/\/print rear node\r\n\tprintf(\"\\n Enqueue node | %d | ln \\n\",newNode->data);\r\n\tPrintQueue(headNode);\r\n\t}\r\n\t\/\/end Enqueue\r\n\t\/\/start Dequeue\r\n\tvoid Dequeue(HEAD *headNode) {\r\n\t\t\/\/get front node\r\n\t\tNODE *frontNode = headNode->front;\r\n\t\t\/\/set front node to next node\r\n\t\theadNode->front = frontNode->next;\r\n\t\t\/\/decrease count\r\n\t\theadNode->count--;\r\n\t\t\/\/check is last node\r\n\t\tif(headNode->count==0)\r\n\t\t\theadNode->rear = NULL;\r\n\t\t\/\/print front node\r\n\t\tprintf(\"\\n Dequeue node | %d | out \\n\",frontNode->data);\r\n\t\tPrintQueue(headNode);\r\n\t}\r\n\/\/end Dequeue\r\n\r\nmain() {\r\n\tHEAD *headNode;\r\n\theadNode = (HEAD*)malloc(sizeof(HEAD));\r\n\theadNode->count=0;\r\n\theadNode->front=NULL;\r\n\theadNode->rear=NULL;\r\n\tEnqueue(headNode,2);\r\n\tEnqueue(headNode,4);\r\n\tEnqueue(headNode,6);\r\n\tEnqueue(headNode,8);\r\n\tEnqueue(headNode,10);\r\n\tEnqueue(headNode,12);\r\n\t\r\n\tDequeue(headNode);\r\n\tDequeue(headNode);\r\n\t\r\n\t\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#include typedef struct head { struct node *front; int count; struct node *rear; }HEAD; typedef struct node { int data; struct node *next; }NODE; \/\/start PrintQueue void PrintQueue(HEAD *headNode) { NODE *printNode=headNode->front; int numberOfQueue = headNode->count; int tempData[numberOfQueue]; printf(&#8220;\\n&#8212;&#8212;&#8212;-Print Queue&#8212;&#8212;&#8212;&#8211;\\n&#8221;); while(printNode!=NULL) { \/\/get data into array for display tempData[numberOfQueue-1] = printNode->data; printNode = printNode->next; numberOfQueue&#8211;; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[43,54,9],"tags":[],"class_list":["post-474","post","type-post","status-publish","format-standard","hentry","category-c","category-homework","category-private"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3OMEb-7E","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/posts\/474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474"}],"version-history":[{"count":1,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions\/475"}],"wp:attachment":[{"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}