

{"id":145776,"date":"2025-07-09T18:40:51","date_gmt":"2025-07-09T13:10:51","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=145776"},"modified":"2025-07-09T18:40:51","modified_gmt":"2025-07-09T13:10:51","slug":"restaurant-order-processing-system-using-data-structures","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/","title":{"rendered":"DSA Project &#8211; Restaurant Order Processing System"},"content":{"rendered":"<h3>Program 1<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/\/ Project: Restaurant Order Processing System(Based on Doubly linked list and DQUEUE)\r\n\/*   \r\n Features:\r\n1. Add order at the end of the queue (new order)\r\n2. Serve the first order (remove from front)\r\n3. Cancel the last order (remove from end)\r\n4. View all pending orders (from first to last)\r\n*\/\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;string.h&gt;\r\n\r\n#define MAX_NAME 50\r\n#define MAX_ITEM 50\r\n\r\ntypedef struct Order      \/\/ Node\r\n{\r\n    struct Order* prev;\r\n    int orderId;\r\n    char customerName[MAX_NAME];\r\n    char foodItem[MAX_ITEM];\r\n    struct Order* next;\r\n} Order;\r\n\r\nOrder* head = NULL;\r\nOrder* tail = NULL;\r\nint nextOrderId = 1;\r\n\r\n\/\/ Create a new order\r\nOrder* createOrder(char* customerName, char* foodItem) \r\n{\r\n    Order* newOrder = (Order*)malloc(sizeof(Order));   \/\/ New\r\n    newOrder-&gt;orderId = nextOrderId++;\r\n    strcpy(newOrder-&gt;customerName, customerName);\r\n    strcpy(newOrder-&gt;foodItem, foodItem);\r\n    newOrder-&gt;prev = NULL;\r\n    newOrder-&gt;next = NULL;\r\n    return newOrder;\r\n}\r\n\r\n\/\/ Add order at the end\r\nvoid addOrder(char* customerName, char* foodItem) \r\n{\r\n    Order* newOrder = createOrder(customerName, foodItem);\r\n    if (head == NULL) \r\n    {\r\n        head = tail = newOrder;\r\n    } else \r\n    {\r\n        tail-&gt;next = newOrder;\r\n        newOrder-&gt;prev = tail;\r\n        tail = newOrder;\r\n    }\r\n    printf(\"Order #%d added for %s: %s\\n\", newOrder-&gt;orderId, customerName, foodItem);\r\n}\r\n\r\n\/\/ Serve the first order\r\nvoid serveOrder() \r\n{\r\n    if (head == NULL) \r\n    {\r\n        printf(\"No orders to serve.\\n\");\r\n        return;\r\n}\r\n    Order* temp = head;\r\n    printf(\"Serving Order #%d: %s (%s)\\n\", temp-&gt;orderId, temp-&gt;customerName, temp-&gt;foodItem);\r\n    head = head-&gt;next;\r\n    if (head!=NULL)\r\n        head-&gt;prev = NULL;\r\n    else\r\n        tail = NULL; \/\/ List became empty\r\n    free(temp);\r\n}\r\n\r\n\/\/ Cancel the last order\r\nvoid cancelLastOrder() {\r\n    if (tail == NULL) {\r\n        printf(\"No orders to cancel.\\n\");\r\n        return;\r\n    }\r\n    Order* temp = tail;\r\n    printf(\"Cancelling Order #%d: %s (%s)\\n\", temp-&gt;orderId, temp-&gt;customerName, temp-&gt;foodItem);\r\n    tail = tail-&gt;prev;\r\n    if (tail)\r\n        tail-&gt;next = NULL;\r\n    else\r\n        head = NULL; \/\/ List became empty\r\n    free(temp);\r\n}\r\n\r\n\/\/ View all orders\r\nvoid viewOrders()\r\n {\r\n    if (head == NULL) \r\n    {\r\n        printf(\"No pending orders.\\n\");\r\n        return;\r\n    }\r\n    printf(\"\\n--- Pending Orders ---\\n\");\r\n    Order* temp = head;\r\n    while (temp!=NULL)\r\n     {\r\n        printf(\"Order #%d | Customer: %s | Item: %s\\n\", temp-&gt;orderId, temp-&gt;customerName, temp-&gt;foodItem);\r\n        temp = temp-&gt;next;\r\n    }\r\n}\r\nvoid  viewOrderByID()\r\n{\r\n    int id;\r\n    \r\n   if(head==NULL)\r\n   {\r\n     printf(\"No pending orders.\\n\");\r\n     return;\r\n   }  \r\n  else\r\n  {\r\n    printf(\"Enter Order id :\");\r\n    scanf(\"%d\",&amp;id);\r\n\r\n      Order *temp=head;\r\n      while(temp!=NULL)\r\n      {\r\n          if(id==temp-&gt;orderId)\r\n         { \r\n          printf(\"Order #%d | Customer: %s | Item: %s\\n\", temp-&gt;orderId, temp-&gt;customerName, temp-&gt;foodItem);\r\n          return;\r\n         }  \r\n         temp=temp-&gt;next;      \r\n      }\r\n      printf(\"No pending orders of  %d id is found.\\n\",id);\r\n\r\n  }   \r\n\r\n}\r\nvoid menu() {\r\n    int choice;\r\n    char name[MAX_NAME];\r\n    char item[MAX_ITEM];\r\n\r\n    while (1) {\r\n        printf(\"\\n==== Restaurant Order System ====\\n\");\r\n        printf(\"1. Add New Order\\n\");\r\n        printf(\"2. Serve First Order\\n\");\r\n        printf(\"3. Cancel Last Order\\n\");\r\n        printf(\"4. View All Orders\\n\");\r\n        printf(\"5. View  Orders By ID\\n\");\r\n        printf(\"6. Exit\\n\");\r\n        printf(\"Enter your choice: \");\r\n        scanf(\"%d\", &amp;choice);\r\n        getchar();  \/\/ consume newline\r\n\r\n        switch (choice) {\r\n            case 1:\r\n                printf(\"Enter customer name: \");\r\n                fgets(name, MAX_NAME, stdin);\r\n                name[strcspn(name, \"\\n\")] = 0; \/\/ remove newline\r\n                printf(\"Enter food item: \");\r\n                fgets(item, MAX_ITEM, stdin);\r\n                item[strcspn(item, \"\\n\")] = 0;\r\n                addOrder(name, item);  \r\n                break;\r\n            case 2:\r\n                serveOrder();\r\n                break;\r\n            case 3:\r\n                cancelLastOrder();\r\n                break;\r\n            case 4:\r\n                viewOrders();\r\n                break;\r\n                case 5:\r\n                 viewOrderByID();\r\n                 break;    \r\n            case 6:\r\n                printf(\"Exiting system.\\n\");\r\n                return;\r\n            default:\r\n                printf(\"Invalid option. Try again.\\n\");\r\n        }\r\n    }\r\n}\r\n\r\nint main() \r\n{\r\n    menu();\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Program 1 \/\/ Project: Restaurant Order Processing System(Based on Doubly linked list and DQUEUE) \/* Features: 1. Add order at the end of the queue (new order) 2. Serve the first order (remove from&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24020],"tags":[24331,34845,34846,34847,34844,34807,34861,34859,34860],"class_list":["post-145776","post","type-post","status-publish","format-standard","hentry","category-data-structure-tutorials","tag-data-structures","tag-data-structures-practical","tag-data-structures-program","tag-data-structures-project","tag-dsa","tag-restaurant-order-processing-system","tag-restaurant-order-processing-system-in-data-structures","tag-restaurant-order-processing-system-project","tag-restaurant-order-processing-system-using-data-structures"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>DSA Project - Restaurant Order Processing System - DataFlair<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DSA Project - Restaurant Order Processing System - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Program 1 \/\/ Project: Restaurant Order Processing System(Based on Doubly linked list and DQUEUE) \/* Features: 1. Add order at the end of the queue (new order) 2. Serve the first order (remove from&#046;&#046;&#046;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-09T13:10:51+00:00\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DSA Project - Restaurant Order Processing System - DataFlair","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/","og_locale":"en_US","og_type":"article","og_title":"DSA Project - Restaurant Order Processing System - DataFlair","og_description":"Program 1 \/\/ Project: Restaurant Order Processing System(Based on Doubly linked list and DQUEUE) \/* Features: 1. Add order at the end of the queue (new order) 2. Serve the first order (remove from&#46;&#46;&#46;","og_url":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2025-07-09T13:10:51+00:00","author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"DSA Project &#8211; Restaurant Order Processing System","datePublished":"2025-07-09T13:10:51+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/"},"wordCount":9,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"keywords":["Data Structures","data structures practical","data structures program","data structures project","dsa","restaurant order processing system","restaurant order processing system in data structures","restaurant order processing system project","restaurant order processing system using data structures"],"articleSection":["Data Structure Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/","url":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/","name":"DSA Project - Restaurant Order Processing System - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"datePublished":"2025-07-09T13:10:51+00:00","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/restaurant-order-processing-system-using-data-structures\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Data Structure Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/data-structure-tutorials\/"},{"@type":"ListItem","position":3,"name":"DSA Project &#8211; Restaurant Order Processing System"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/145776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=145776"}],"version-history":[{"count":2,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/145776\/revisions"}],"predecessor-version":[{"id":145789,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/145776\/revisions\/145789"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=145776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=145776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=145776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}