{"id":9903,"date":"2022-09-25T23:43:05","date_gmt":"2022-09-25T23:43:05","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=9903"},"modified":"2022-10-10T08:34:11","modified_gmt":"2022-10-10T08:34:11","slug":"data-structures-using-c-array-linked-list-stack","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/","title":{"rendered":"Data Structures Using C | Array | Linked List | Stack"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg\" alt=\"\" \/><\/p>\n<\/p>\n<h3>What are Data structures using C?<\/h3>\n<p>Data structure is a storage that is used to store and organize data. It is a way of arranging data on a computer so that it can be accessed and updated efficiently.<br \/>\nDepending on your requirement and project, it is important to choose the right data structure for your project. For example, if you want to store data sequentially in the memory, then you can go for the Array data structure.<\/p>\n<p>Data Structures using C is an important part of Programming. Get a better understanding of problems by watching these <a href=\"https:\/\/www.prepbytes.com\/preparation-videos\/data-structures-and-algorithms\" title=\"video tutorials\">video tutorials<\/a> created by expert mentors at <a href=\"https:\/\/www.prepbytes.com\/\" title=\"Prepbytes\">Prepbytes<\/a>.<\/p>\n<h3>Why are Data Structures important?<\/h3>\n<p>Data structure provides a way of organizing, managing, and storing data efficiently. With the help of data structure, the data items can be traversed easily. Data structure provides efficiency, reusability and abstraction. It plays an important role in enhancing the performance of a program because the main function of the program is to store and retrieve the user\u2019s data as fast as possible.<br \/>\nAs applications are becoming more complex and the amount of data is increasing day by day, which may cause problems with processing speed, searching data, handling multiple requests etc.<\/p>\n<h3>Types of Data Structures<\/h3>\n<p>Basically, data structures are divided into two categories:<\/p>\n<ul>\n<li>Linear data structure<\/li>\n<li>Non-linear data structure<\/li>\n<\/ul>\n<p>Let&#8217;s learn about each type in detail.<\/p>\n<p>In linear data structures, the elements are arranged in sequence one after the other. Since elements are arranged in particular order, they are easy to implement.<br \/>\nHowever, when the complexity of the program increases, the linear data structures might not be the best choice because of operational complexities.<br \/>\nPopular linear data structures using C are:<\/p>\n<h3>Array:<\/h3>\n<p>Arrays are defined as the collection of similar types of data items stored at contiguous memory locations. It is one of the simplest data structures where each data element can be randomly accessed by using its index number.<br \/>\nIn C programming, they are the derived data types that can store the primitive type of data such as int, char, double, float, etc. For example, if we want to store the marks of a student in 6 subjects, then we don&#8217;t need to define a different variable for the marks in different subjects. Instead, we can define an array that can store the marks in each subject at the contiguous memory locations.<\/p>\n<h3>Representation of an array<\/h3>\n<p>We can represent an array in various ways in different programming languages. As an illustration, let&#8217;s see the declaration of array in C language &#8211;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911431976-1-01.png\" alt=\"\" \/><\/p>\n<p>As per the above illustration, there are some of the following important points &#8211;<\/p>\n<ul>\n<li>Index starts with 0.<\/li>\n<li>The array&#8217;s length is 10, which means we can store 10 elements.<\/li>\n<li>Each element in the array can be accessed via its index.<\/li>\n<\/ul>\n<h3>Implementation:<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_9907 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_9907 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_9907 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_9907 .wpsm_nav-tabs > li.active > a, #tab_container_9907 .wpsm_nav-tabs > li.active > a:hover, #tab_container_9907 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_9907 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_9907 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_9907 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_9907 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_9907 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_9907 .wpsm_nav-tabs > li > a:hover , #tab_container_9907 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_9907 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_9907 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_9907 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_9907 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_9907 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_9907 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_9907 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_9907 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_9907 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_9907 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_9907 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_9907\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_9907\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_9907_1\" aria-controls=\"tabs_desc_9907_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_9907\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_9907_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include &lt;stdio.h&gt;  \r\nint main()  \r\n{  \r\n    int arr[20] = { 18, 30, 15, 70, 12 };  \r\n    int i, x, pos, n = 5;  \r\n    printf(&quot;Array elements before insertion&#92;n&quot;);  \r\n    for (i = 0; i &lt; n; i++)  \r\n        printf(&quot;%d &quot;, arr[i]);  \r\n    printf(&quot;&#92;n&quot;);  \r\n  \r\n    x = 50; \/\/ element to be inserted  \r\n    pos = 4;  \r\n    n++;  \r\n  \r\n    for (i = n-1; i &gt;= pos; i--)  \r\n        arr[i] = arr[i - 1];  \r\n    arr[pos - 1] = x;  \r\n    printf(&quot;Array elements after insertion&#92;n&quot;);  \r\n    for (i = 0; i &lt; n; i++)  \r\n        printf(&quot;%d &quot;, arr[i]);  \r\n    printf(&quot;&#92;n&quot;);  \r\n    return 0;  \r\n}  \r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_9907 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_9907 a\"),jQuery(\"#tab-content_9907\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<h3>Linked List:<\/h3>\n<p>Linked list is a linear data structure that includes a series of connected nodes. Linked list can be defined as the nodes that are randomly stored in the memory. A node in the linked list contains two parts, i.e., first is the data part and second is the address part. The last node of the list contains a pointer to the null. After array, linked list is the second most used data structure. In a linked list, every link contains a connection to another link.<\/p>\n<pre><code>struct node  \n{  \nint data;  \nstruct node *next;  \n} <\/code><\/pre>\n<h3>Representation of a Linked list<\/h3>\n<p>Linked list can be represented as the connection of nodes in which each node points to the next node of the list. The representation of the linked list is shown below &#8211;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911535484-1-02.png\" alt=\"\" \/><\/p>\n<pre><code>struct node   \n{  \n    int data;   \n    struct node *next;  \n};  \nstruct node *head, *ptr;   \nptr = (struct node *)malloc(sizeof(struct node *));  <\/code><\/pre>\n<h3>Linked list is useful because &#8211;<\/h3>\n<ul>\n<li>It allocates the memory dynamically. All the nodes of the linked list are non-contiguously stored in the memory and linked together with the help of pointers.<\/li>\n<li>In the linked list, size is no longer a problem since we do not need to define its size at the time of declaration. List grows as per the program&#8217;s demand and is limited to the available memory space.<\/li>\n<\/ul>\n<h3>Types of Linked list<\/h3>\n<p>Linked list is classified into the following types &#8211;<\/p>\n<ul>\n<li><strong>Singly-linked list<\/strong> &#8211; Singly linked list can be defined as the collection of an ordered set of elements. A node in the singly linked list consists of two parts: data part and link part. Data part of the node stores actual information that is to be represented by the node, while the link part of the node stores the address of its immediate successor.<\/li>\n<li><strong>Doubly linked list<\/strong> &#8211; Doubly linked list is a complex type of linked list in which a node contains a pointer to the previous as well as the next node in the sequence. Therefore, in a doubly-linked list, a node consists of three parts: node data, pointer to the next node in sequence (next pointer), and pointer to the previous node (previous pointer).<\/li>\n<li><strong>Circular singly linked list<\/strong> &#8211; In a circular singly linked list, the last node of the list contains a pointer to the first node of the list. We can have circular singly linked lists as well as circular doubly linked lists.<\/li>\n<li><strong>Circular doubly linked list<\/strong> &#8211; Circular doubly linked list is a more complex type of data structure in which a node contains pointers to its previous node as well as the next node. Circular doubly linked list doesn&#8217;t contain NULL in any of the nodes. The last node of the list contains the address of the first node of the list. The first node of the list also contains the address of the last node in its previous pointer.<\/li>\n<\/ul>\n<h3>Implementation:<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_9906 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_9906 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_9906 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_9906 .wpsm_nav-tabs > li.active > a, #tab_container_9906 .wpsm_nav-tabs > li.active > a:hover, #tab_container_9906 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_9906 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_9906 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_9906 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_9906 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_9906 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_9906 .wpsm_nav-tabs > li > a:hover , #tab_container_9906 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_9906 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_9906 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_9906 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_9906 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_9906 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_9906 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_9906 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_9906 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_9906 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_9906 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_9906 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_9906\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_9906\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_9906_1\" aria-controls=\"tabs_desc_9906_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_9906\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_9906_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;string.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;stdbool.h&gt;\r\n\r\nstruct node {\r\n   int data;\r\n   int key;\r\n   struct node *next;\r\n};\r\nstruct node *head = NULL;\r\nstruct node *current = NULL;\r\n\r\n\/\/display the list\r\nvoid printList(){\r\n   struct node *ptr = head;\r\n   printf(&quot;&#92;n[ &quot;);\r\n   \r\n   \/\/start from the beginning\r\n   while(ptr != NULL){        \r\n      printf(&quot;(%d,%d) &quot;,ptr-&gt;key,ptr-&gt;data);\r\n      ptr = ptr-&gt;next;\r\n   }\r\n   printf(&quot; ]&quot;);\r\n}\r\n\/\/insert link at the first location\r\nvoid insertFirst(int key, int data){\r\n   \/\/create a link\r\n   struct node *link = (struct node*) malloc(sizeof(struct node));\r\n   link-&gt;key = key;\r\n   link-&gt;data = data;\r\n   \r\n   \/\/point it to old first node\r\n   link-&gt;next = head;\r\n   \r\n   \/\/point first to new first node\r\n   head = link;\r\n}\r\n\/\/delete first item\r\nstruct node* deleteFirst(){\r\n   \/\/save reference to first link\r\n   struct node *tempLink = head;\r\n   \r\n   \/\/mark next to first link as first \r\n   head = head-&gt;next;\r\n   \r\n   \/\/return the deleted link\r\n   return tempLink;\r\n}\r\n\/\/is list empty\r\nbool isEmpty(){\r\n   return head == NULL;\r\n}\r\nint length(){\r\n   int length = 0;\r\n   struct node *current;\r\n   for(current = head; current!=NULL;\r\n      current = current-&gt;next){\r\n      length++;\r\n   }\r\n   return length;\r\n}\r\n\/\/find a link with given key\r\nstruct node* find(int key){\r\n   \/\/start from the first link\r\n   struct node* current = head;\r\n\r\n   \/\/if list is empty\r\n   if(head == NULL){\r\n      return NULL;\r\n   }\r\n   \/\/navigate through list\r\n   while(current-&gt;key != key){\r\n      \/\/if it is last node\r\n      if(current-&gt;next == NULL){\r\n         return NULL;\r\n      } else {\r\n         \/\/go to next link\r\n         current = current-&gt;next;\r\n      }\r\n   }\r\n   \/\/if data found, return the current Link\r\n   return current;\r\n}\r\n\/\/delete a link with given key\r\nstruct node* delete(int key){\r\n   \/\/start from the first link\r\n   struct node* current = head;\r\n   struct node* previous = NULL;\r\n   \r\n   \/\/if list is empty\r\n   if(head == NULL){\r\n      return NULL;\r\n   }\r\n   \/\/navigate through list\r\n   while(current-&gt;key != key){\r\n      \/\/if it is last node\r\n      if(current-&gt;next == NULL){\r\n         return NULL;\r\n      } else {\r\n         \/\/store reference to current link\r\n         previous = current;\r\n         \r\n         \/\/move to next link\r\n         current = current-&gt;next;             \r\n      }\r\n   }\r\n   \/\/found a match, update the link\r\n   if(current == head) {\r\n      \/\/change first to point to next link\r\n      head = head-&gt;next;\r\n   } else {\r\n      \/\/bypass the current link\r\n      previous-&gt;next = current-&gt;next;\r\n   }\r\n   return current;\r\n}\r\nvoid sort(){\r\n   int i, j, k, tempKey, tempData ;\r\n   struct node *current;\r\n   struct node *next;\r\n   int size = length();\r\n   k = size ;\r\n   for ( i = 0 ; i &lt; size - 1 ; i++, k-- ) {\r\n      current = head ;\r\n      next = head-&gt;next ;\r\n      for ( j = 1 ; j &lt; k ; j++ ) {            \r\n         if ( current-&gt;data &gt; next-&gt;data ) {\r\n            tempData = current-&gt;data ;\r\n            current-&gt;data = next-&gt;data;\r\n            next-&gt;data = tempData ;\r\n\r\n            tempKey = current-&gt;key;\r\n            current-&gt;key = next-&gt;key;\r\n            next-&gt;key = tempKey;\r\n         }\r\n         current = current-&gt;next;\r\n         next = next-&gt;next;                        \r\n      }\r\n   }\r\n}\r\nvoid reverse(struct node** head_ref) {\r\n   struct node* prev   = NULL;\r\n   struct node* current = *head_ref;\r\n   struct node* next;\r\n   while (current != NULL) {\r\n      next  = current-&gt;next;  \r\n      current-&gt;next = prev;   \r\n      prev = current;\r\n      current = next;\r\n   }\r\n   *head_ref = prev;\r\n}\r\n\r\nmain() {\r\n   insertFirst(1,10);\r\n   insertFirst(2,20);\r\n   insertFirst(3,30);\r\n   insertFirst(4,1);\r\n   insertFirst(5,40);\r\n   insertFirst(6,56); \r\n\r\n   printf(&quot;Original List: &quot;); \r\n   \/\/print list\r\n   printList();\r\n\r\n   while(!isEmpty()){            \r\n      struct node *temp = deleteFirst();\r\n      printf(&quot;&#92;nDeleted value:&quot;);  \r\n      printf(&quot;(%d,%d) &quot;,temp-&gt;key,temp-&gt;data);        \r\n   }         \r\n   printf(&quot;&#92;nList after deleting all items: &quot;);          \r\n   printList();\r\n   insertFirst(1,10);\r\n   insertFirst(2,20);\r\n   insertFirst(3,30);\r\n   insertFirst(4,1);\r\n   insertFirst(5,40);\r\n   insertFirst(6,56); \r\n   printf(&quot;&#92;nRestored List: &quot;);  \r\n   printList();\r\n   printf(&quot;&#92;n&quot;);  \r\n\r\n   struct node *foundLink = find(4);\r\n   if(foundLink != NULL){\r\n      printf(&quot;Element found: &quot;);  \r\n      printf(&quot;(%d,%d) &quot;,foundLink-&gt;key,foundLink-&gt;data);  \r\n      printf(&quot;&#92;n&quot;);  \r\n   } else {\r\n      printf(&quot;Element not found.&quot;);  \r\n   }\r\n   delete(4);\r\n   printf(&quot;List after deleting an item: &quot;);  \r\n   printList();\r\n   printf(&quot;&#92;n&quot;);\r\n   foundLink = find(4);\r\n   if(foundLink != NULL){\r\n      printf(&quot;Element found: &quot;);  \r\n      printf(&quot;(%d,%d) &quot;,foundLink-&gt;key,foundLink-&gt;data);  \r\n      printf(&quot;&#92;n&quot;);  \r\n   } else {\r\n      printf(&quot;Element not found.&quot;);  \r\n   }\r\n   printf(&quot;&#92;n&quot;);  \r\n   sort();\r\n   printf(&quot;List after sorting the data: &quot;);  \r\n   printList();\r\n   reverse(&amp;head);\r\n   printf(&quot;&#92;nList after reversing the data: &quot;);  \r\n   printList();\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_9906 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_9906 a\"),jQuery(\"#tab-content_9906\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<h3>Stack:<\/h3>\n<p>A Stack is a linear data structure that follows the <strong>LIFO (Last-In-First-Out)<\/strong> principle. Stack has one end, whereas the Queue has two ends <strong>(front and rear)<\/strong>. It contains only one pointer top pointer pointing to the topmost element of the stack. Whenever an element is added in the stack, it is added on the top of the stack, and the element can be deleted only from the stack. In other words, <strong>a stack can be defined as a container in which insertion and deletion can be done from the one end known as the top of the stack<\/strong>.<\/p>\n<h3>Working of Stack<\/h3>\n<p>Stack works on the LIFO pattern. As we can observe in the below figure there are five memory blocks in the stack; therefore, the size of the stack is 5.<br \/>\nSuppose we want to store the elements in a stack and let&#8217;s assume that stack is empty. We have taken the stack of size 5 as shown below in which we are pushing the elements one by one until the stack becomes full.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911555551-1-03.png\" alt=\"\" \/><\/p>\n<p>Since our stack is full as the size of the stack is 5. In the above cases, we can observe that it goes from the top to the bottom when we were entering the new element in the stack. The stack gets filled up from the bottom to the top.<br \/>\nWhen we perform the delete operation on the stack, there is only one way for entry and exit as the other end is closed. It follows the LIFO pattern, which means that the value entered first will be removed last. In the above case, the value 5 is entered first, so it will be removed only after the deletion of all the other elements.<\/p>\n<h3>Standard Stack Operations<\/h3>\n<p><strong>The following are some common operations implemented on the stack:<\/strong><\/p>\n<ul>\n<li><strong>push()<\/strong>: When we insert an element in a stack then the operation is known as a push. If the stack is full then the overflow condition occurs.<\/li>\n<li><strong>pop()<\/strong>: When we delete an element from the stack, the operation is known as a pop. If the stack is empty means that no element exists in the stack, this state is known as an underflow state.<\/li>\n<li><strong>isEmpty()<\/strong>: It determines whether the stack is empty or not.<\/li>\n<li><strong>isFull()<\/strong>: It determines whether the stack is full or not.&#8217;<\/li>\n<li><strong>peek()<\/strong>: It returns the element at the given position.<\/li>\n<\/ul>\n<h3>Implementation:<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_9905 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_9905 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_9905 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_9905 .wpsm_nav-tabs > li.active > a, #tab_container_9905 .wpsm_nav-tabs > li.active > a:hover, #tab_container_9905 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_9905 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_9905 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_9905 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_9905 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_9905 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_9905 .wpsm_nav-tabs > li > a:hover , #tab_container_9905 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_9905 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_9905 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_9905 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_9905 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_9905 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_9905 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_9905 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_9905 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_9905 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_9905 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_9905 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_9905\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_9905\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_9905_1\" aria-controls=\"tabs_desc_9905_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_9905\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_9905_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;string.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;stdbool.h&gt;\r\n\r\n\/\/ size of the stack\r\nint size = 8;       \r\n\r\n\/\/ stack storage\r\nint intArray[8];     \r\n\r\n\/\/ top of the stack\r\nint top = -1;            \r\n\r\n\/\/ Operation : Pop\r\n\/\/ pop item from the top of the stack \r\nint pop() {\r\n   \/\/retrieve data and decrement the top by 1\r\n   return intArray[top--];        \r\n}\r\n\/\/ Operation : Peek\r\n\/\/ view the data at top of the stack \r\nint peek() {       \r\n   \/\/retrieve data from the top\r\n   return intArray[top];\r\n}\r\n\/\/Operation : isFull\r\n\/\/return true if stack is full \r\nbool isFull(){\r\n   return (top == size-1);\r\n}\r\n\r\n\/\/ Operation : isEmpty\r\n\/\/ return true if stack is empty \r\nbool isEmpty(){\r\n   return (top == -1);\r\n}\r\n\/\/ Operation : Push\r\n\/\/ push item on the top of the stack \r\nvoid push(int data) {\r\n   if(!isFull()){\r\n      \/\/ increment top by 1 and insert data \r\n      intArray[++top] = data;\r\n   } else {\r\n      printf(&quot;Cannot add data. Stack is full.&#92;n&quot;);\r\n   }      \r\n}\r\nmain() {\r\n   \/\/ push items on to the stack \r\n   push(3);\r\n   push(5);\r\n   push(9);\r\n   push(1);\r\n   push(12);\r\n   push(15);\r\n\r\n   printf(&quot;Element at top of the stack: %d&#92;n&quot; ,peek());\r\n   printf(&quot;Elements: &#92;n&quot;);\r\n\r\n   \/\/ print stack data \r\n   while(!isEmpty()){\r\n      int data = pop();\r\n      printf(&quot;%d&#92;n&quot;,data);\r\n   }\r\n   printf(&quot;Stack full: %s&#92;n&quot; , isFull()?&quot;true&quot;:&quot;false&quot;);\r\n   printf(&quot;Stack empty: %s&#92;n&quot; , isEmpty()?&quot;true&quot;:&quot;false&quot;);\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_9905 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_9905 a\"),jQuery(\"#tab-content_9905\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p>Test your data structure skills by taking this <a href=\"https:\/\/www.prepbytes.com\/mock-tests\/ds-algo\/set-1\" title=\"Data Structures Using C Mock Test\">Data Structures Using C Mock Test<\/a> designed by experienced mentors at <a href=\"https:\/\/www.prepbytes.com\/\" title=\"PrepBytes\">PrepBytes<\/a>.<\/p>\n<p>We tried to discuss Data Structures using C in this article. We hope this article gives you a better understanding of basics in Data Structures using C. <a href=\"https:\/\/www.prepbytes.com\/\" title=\"Prepbytes\">Prepbytes<\/a> also provides a good collection of <a href=\"https:\/\/www.prepbytes.com\/prepbytes-courses\" title=\"Foundation Courses\">Foundation Courses<\/a> that can help you enhance your coding skills. Want to make sure you ace the interview in one go? Join our <a href=\"https:\/\/www.prepbytes.com\/placement-preparation-program\" title=\"Placement Program\">Placement Program<\/a> that will help you get prepared and land your dream job at MNCs. Mentors of Prepbytes are highly experienced and can provide you with basic, in-depth subject knowledge for better understanding.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What are Data structures using C? Data structure is a storage that is used to store and organize data. It is a way of arranging data on a computer so that it can be accessed and updated efficiently. Depending on your requirement and project, it is important to choose the right data structure for your [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[191],"tags":[],"class_list":["post-9903","post","type-post","status-publish","format-standard","hentry","category-data-structure"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Data Structures Using C | Array | Linked List | PrepBytes Blog<\/title>\n<meta name=\"description\" content=\"We tried to discuss Data Structures using C in this article i.e. array &amp; linked list. We hope this article gives you a better understanding of basics in Data Structures using C\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data Structures Using C | Array | Linked List | PrepBytes Blog\" \/>\n<meta property=\"og:description\" content=\"We tried to discuss Data Structures using C in this article i.e. array &amp; linked list. We hope this article gives you a better understanding of basics in Data Structures using C\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-25T23:43:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-10T08:34:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Data Structures Using C | Array | Linked List | Stack\",\"datePublished\":\"2022-09-25T23:43:05+00:00\",\"dateModified\":\"2022-10-10T08:34:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/\"},\"wordCount\":1444,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg\",\"articleSection\":[\"Data Structure\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/\",\"name\":\"Data Structures Using C | Array | Linked List | PrepBytes Blog\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg\",\"datePublished\":\"2022-09-25T23:43:05+00:00\",\"dateModified\":\"2022-10-10T08:34:11+00:00\",\"description\":\"We tried to discuss Data Structures using C in this article i.e. array & linked list. We hope this article gives you a better understanding of basics in Data Structures using C\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Data Structure\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/data-structure\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Data Structures Using C | Array | Linked List | Stack\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Data Structures Using C | Array | Linked List | PrepBytes Blog","description":"We tried to discuss Data Structures using C in this article i.e. array & linked list. We hope this article gives you a better understanding of basics in Data Structures using C","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:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/","og_locale":"en_US","og_type":"article","og_title":"Data Structures Using C | Array | Linked List | PrepBytes Blog","og_description":"We tried to discuss Data Structures using C in this article i.e. array & linked list. We hope this article gives you a better understanding of basics in Data Structures using C","og_url":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-09-25T23:43:05+00:00","article_modified_time":"2022-10-10T08:34:11+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Data Structures Using C | Array | Linked List | Stack","datePublished":"2022-09-25T23:43:05+00:00","dateModified":"2022-10-10T08:34:11+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/"},"wordCount":1444,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg","articleSection":["Data Structure"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/","url":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/","name":"Data Structures Using C | Array | Linked List | PrepBytes Blog","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg","datePublished":"2022-09-25T23:43:05+00:00","dateModified":"2022-10-10T08:34:11+00:00","description":"We tried to discuss Data Structures using C in this article i.e. array & linked list. We hope this article gives you a better understanding of basics in Data Structures using C","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1663911571290-Topic.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/data-structures-using-c-array-linked-list-stack\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Data Structure","item":"https:\/\/prepbytes.com\/blog\/category\/data-structure\/"},{"@type":"ListItem","position":3,"name":"Data Structures Using C | Array | Linked List | Stack"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/9903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=9903"}],"version-history":[{"count":4,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/9903\/revisions"}],"predecessor-version":[{"id":10174,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/9903\/revisions\/10174"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=9903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=9903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=9903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}