Write code in C for Circular Queue through Array?

Data Structure >   Queue Data Structure >   Circular Queue  

Long Question

478


Answer:


#include <stdio.h>
#include<ctype.h>
# define MAXSIZE 200
int queue[MAXSIZE];
int front=-1, rear=-1; //index pointing to the top of stack
void main()
{
void enqueue(int);
int dequeue();
int will=1,i,num,ch;
while(will ==1)
{
printf("MAIN MENU:
1. Enqueue
2.Dequeue
3. Check Queue Full
4. Check Queue Empty ");
Scanf ("%d", &ch);
switch(ch)
{
case 1: printf("Enter the data to add... ");
scanf("%d", &num);
enqueue(num);
break;
case 2: num=dequeue();
if(num= = -1)
printf( </p>
                                          
                                        <hr>
                                        
                              <div style="text-align:center">
                              <a href="#list" class="btn btn-info btn-sm main-gradient-tutorials">Go to Question List</a>
                              </div>
                              
                              <div class = "shadow p-3 mt-2" style = "border-radius: 10px;">
                               <div class='col m-3'><p> <i class='fa fa-info-circle'></i> <small>This Particular section is dedicated to <b>Question & Answer</b> only. If you want learn more about <b>Data Structure</b>. Then you can visit below links to get more depth on this subject.  </small></p></div><div class='col m-3'><div class="row">
     <div class="col bg-light m-2 shadow btn btn-success"><a href="https://www.atnyla.com/syllabus/data-structure/3">Data Structure Syllabus </a> </div>
     <div class="col bg-light m-2 shadow btn btn-success"><a href="https://www.atnyla.com/tutorial/about-dsa/3/295">Data Structure Tutorial</a> </div>  
     <div class="col bg-light m-2 shadow btn btn-success"><a href="https://www.atnyla.com/array/3/54">Data Structure Programs </a> </div> 
     <div class="col bg-light m-2 shadow btn btn-success"><a href="https://www.atnyla.com/qa/data-structure-introduction/3/56">Data Structure Question Answers </a> </div>
     <div class="col bg-light m-2 shadow btn btn-success"><a href="https://www.atnyla.com/general-knowledge/95/254">Data Structure MCQ </a> </div>  
</div> 
<hr></div><hr style='height:3px;border-width:0;color:gray;background-color:gray'>                              </div>
                                 
                              <br>
                             <div class="shadow p-3 mb-5 bg-body rounded">
                               <a href="/tutorial/about-c-tutorial/1/152" class="btn btn-sm btn-default"># C Tutorials</a> 
                               <a href="/tutorial/java/0/0" class="btn btn-sm btn-default"># JAVA Tutorials</a>
                               <a href="/tutorial/about-html5-tutorial/2/233" class="btn btn-sm btn-default"># HTML Tutorials</a>
                           
                              <a href="https://www.atnyla.com/tutorial/about-tutorial/6/395" class="btn btn-sm btn-default"># Computer Fundamental</a> 
                               <a href="https://www.atnyla.com/tutorial/about-dsa/3/295" class="btn btn-sm btn-default"># Data Structure</a>
                               <a href="https://www.atnyla.com/tutorial/about-dbms-tutorial/13/713" class="btn btn-sm btn-default"># DBMS Tutorials</a>
                           
                              <a href="https://www.atnyla.com/tutorial/about-sql-tutorial/5/355" class="btn btn-sm btn-default">SQL</a> 
                               <a href="https://www.atnyla.com/tutorial/about-c-tutorial/8/468" class="btn btn-sm btn-default"># C# Language</a>
                               <a href="https://www.atnyla.com/tutorial/about-r-tutorial/7/409" class="btn btn-sm btn-default"># R Language</a>
                            
                              <a href="https://www.atnyla.com/tutorial/about-php-tutorial/12/604" class="btn btn-sm btn-default"># PHP</a> 
                               <a href="https://www.atnyla.com/tutorial/about-python-tutorial/11/597" class="btn btn-sm btn-default"># Python</a>
                               <a href="https://www.atnyla.com/tutorial/about-vue-js-tutorial/14/765" class="btn btn-sm btn-default"># Vue JS</a>
                             </div>
                             
                             <hr>
                             <h3>Join Our telegram group to ask Questions </h3>
                             <p> Click below button to join our groups. </p>
                             <div class="row">
                                 <div class="col m-2 bg-light shadow btn btn-success">
                                   <a href="https://t.me/atnyla"  rel="nofollow" target="_blank"> Ask Question - CSE </a>
                                 </div>  
                                  <div class="col m-2 bg-light shadow btn btn-success">
                                    <a href="https://t.me/ComputerLanguageWithRumman"  rel="nofollow" target="_blank"> Programming Language - PDF</a>
                                </div> 
                            </div>
                                        
                              <br>
                               
                            </div> 
                        </div>
                    </div>
                   <div class="col-lg-5">
                
                            <ul class="list-group" >
                                <li id="list" class="list-group-item d-flex justify-content-between align-items-center main-gradient-tutorials mb-2"><strong>Related Program List</strong></li>
                                         <div class="list-group divStyleQuestion" style="border:1px solid #e0e0e0;padding:8px">
            <div class="d-flex w-100 justify-content-between">
              <a href="/qanswer/what-is-a-priority-queue-question/59/582">
                  <h5 class="mb-1" style="color:#194757;">582. &nbsp;What is a Priority Queue?</h5>
              </a>
            </div>
                        <div class="d-flex w-100 justify-content-between">
                <a style="color:#9e9d9d;" href="/tutorial/priority-queue-implementation-using-array/3/322">
                    <small># Tutorial: Priority Queue Implementation using Array</small> 
                </a>
            </div>
           
                        <a style="color:#9e9d9d;" href="/qa/-/3/59">
                <small><i class="fa fa-code" aria-hidden="true"></i> Question: Queue Data Structure</small>
            </a>
                                  <span class="float-end" style="color:#9e9d9d"> <small><i class="fa fa-check" aria-hidden="true"></i> Long </small></span>
                            </div>
      
            <div class="list-group divStyleQuestion" style="border:1px solid #e0e0e0;padding:8px">
            <div class="d-flex w-100 justify-content-between">
              <a href="/qanswer/applications-of-graph-question/73/759">
                  <h5 class="mb-1" style="color:#194757;">759. &nbsp;Applications of graph?</h5>
              </a>
            </div>
                        <div class="d-flex w-100 justify-content-between">
                <a style="color:#9e9d9d;" href="/tutorial/graph-in-data-structure/3/383">
                    <small># Tutorial: Graph in Data Structure</small> 
                </a>
            </div>
           
                        <a style="color:#9e9d9d;" href="/qa/-/3/73">
                <small><i class="fa fa-code" aria-hidden="true"></i> Question: Graph</small>
            </a>
                                  <span class="float-end" style="color:#9e9d9d"> <small><i class="fa fa-check" aria-hidden="true"></i> Long </small></span>
                            </div>
      
            <div class="list-group divStyleQuestion" style="border:1px solid #e0e0e0;padding:8px">
            <div class="d-flex w-100 justify-content-between">
              <a href="/qanswer/what-is-data-structures-question/56/972">
                  <h5 class="mb-1" style="color:#194757;">972. &nbsp;What is Data Structures?</h5>
              </a>
            </div>
                        <div class="d-flex w-100 justify-content-between">
                <a style="color:#9e9d9d;" href="/tutorial/about-dsa/3/295">
                    <small># Tutorial: About DSA</small> 
                </a>
            </div>
           
                        <a style="color:#9e9d9d;" href="/qa/-/3/56">
                <small><i class="fa fa-code" aria-hidden="true"></i> Question: Data Structure Introduction</small>
            </a>
                                  <span class="float-end" style="color:#9e9d9d"> <small><i class="fa fa-check" aria-hidden="true"></i> Long </small></span>
                            </div>
      
            <div class="list-group divStyleQuestion" style="border:1px solid #e0e0e0;padding:8px">
            <div class="d-flex w-100 justify-content-between">
              <a href="/qanswer/why-we-should-learn-data-structure-question/56/973">
                  <h5 class="mb-1" style="color:#194757;">973. &nbsp;Why we should learn Data Structure?</h5>
              </a>
            </div>
                        <div class="d-flex w-100 justify-content-between">
                <a style="color:#9e9d9d;" href="/tutorial/about-dsa/3/295">
                    <small># Tutorial: About DSA</small> 
                </a>
            </div>
           
                        <a style="color:#9e9d9d;" href="/qa/-/3/56">
                <small><i class="fa fa-code" aria-hidden="true"></i> Question: Data Structure Introduction</small>
            </a>
                                  <span class="float-end" style="color:#9e9d9d"> <small><i class="fa fa-check" aria-hidden="true"></i> Long </small></span>
                            </div>
      
            <div class="list-group divStyleQuestion" style="border:1px solid #e0e0e0;padding:8px">
            <div class="d-flex w-100 justify-content-between">
              <a href="/qanswer/what-is-a-linear-data-structure-name-a-few-examples-question/56/974">
                  <h5 class="mb-1" style="color:#194757;">974. &nbsp;What is a Linear Data Structure? Name a few examples.</h5>
              </a>
            </div>
                        <div class="d-flex w-100 justify-content-between">
                <a style="color:#9e9d9d;" href="/tutorial/various-data-structures/3/298">
                    <small># Tutorial: Various Data structures</small> 
                </a>
            </div>
           
                        <a style="color:#9e9d9d;" href="/qa/-/3/56">
                <small><i class="fa fa-code" aria-hidden="true"></i> Question: Data Structure Introduction</small>
            </a>
                                  <span class="float-end" style="color:#9e9d9d"> <small><i class="fa fa-check" aria-hidden="true"></i> Long </small></span>
                            </div>
      
            <div class="list-group divStyleQuestion" style="border:1px solid #e0e0e0;padding:8px">
            <div class="d-flex w-100 justify-content-between">
              <a href="/qanswer/what-is-a-non-linear-data-structure-name-a-few-examples-question/56/975">
                  <h5 class="mb-1" style="color:#194757;">975. &nbsp;What is a non-Linear Data Structure? Name a few examples.</h5>
              </a>
            </div>
                        <div class="d-flex w-100 justify-content-between">
                <a style="color:#9e9d9d;" href="/tutorial/various-data-structures/3/298">
                    <small># Tutorial: Various Data structures</small> 
                </a>
            </div>
           
                        <a style="color:#9e9d9d;" href="/qa/-/3/56">
                <small><i class="fa fa-code" aria-hidden="true"></i> Question: Data Structure Introduction</small>
            </a>
                                  <span class="float-end" style="color:#9e9d9d"> <small><i class="fa fa-check" aria-hidden="true"></i> Long </small></span>
                            </div>
      
            <div class="list-group divStyleQuestion" style="border:1px solid #e0e0e0;padding:8px">
            <div class="d-flex w-100 justify-content-between">
              <a href="/qanswer/applications-of-queue/59/976">
                  <h5 class="mb-1" style="color:#194757;">976. &nbsp;Applications of Queue?</h5>
              </a>
            </div>
                        <div class="d-flex w-100 justify-content-between">
                <a style="color:#9e9d9d;" href="/tutorial/queue-introduction/3/318">
                    <small># Tutorial: Queue Introduction</small> 
                </a>
            </div>
           
                        <a style="color:#9e9d9d;" href="/qa/-/3/59">
                <small><i class="fa fa-code" aria-hidden="true"></i> Question: Queue Data Structure</small>
            </a>
                                  <span class="float-end" style="color:#9e9d9d"> <small><i class="fa fa-check" aria-hidden="true"></i> Long </small></span>
                            </div>
      
            <div class="list-group divStyleQuestion" style="border:1px solid #e0e0e0;padding:8px">
            <div class="d-flex w-100 justify-content-between">
              <a href="/qanswer/traversal-in-array-using-python/54/1184">
                  <h5 class="mb-1" style="color:#194757;">1184. &nbsp;Traversal in Array using Python</h5>
              </a>
            </div>
                        <div class="d-flex w-100 justify-content-between">
                <a style="color:#9e9d9d;" href="/tutorial/traversal/3/522">
                    <small># Tutorial: Traversal</small> 
                </a>
            </div>
           
                        <a style="color:#9e9d9d;" href="/qa/-/3/54">
                <small><i class="fa fa-code" aria-hidden="true"></i> Question: Array</small>
            </a>
                                  <span class="float-end" style="color:#9e9d9d"> <small><i class="fa fa-check" aria-hidden="true"></i> Long </small></span>
                            </div>
      
            <div class="list-group divStyleQuestion" style="border:1px solid #e0e0e0;padding:8px">
            <div class="d-flex w-100 justify-content-between">
              <a href="/qanswer/selection-in-array-python/54/1185">
                  <h5 class="mb-1" style="color:#194757;">1185. &nbsp;Selection in Array Python</h5>
              </a>
            </div>
                        <div class="d-flex w-100 justify-content-between">
                <a style="color:#9e9d9d;" href="/tutorial/selection/3/523">
                    <small># Tutorial: Selection</small> 
                </a>
            </div>
           
                        <a style="color:#9e9d9d;" href="/qa/-/3/54">
                <small><i class="fa fa-code" aria-hidden="true"></i> Question: Array</small>
            </a>
                                  <span class="float-end" style="color:#9e9d9d"> <small><i class="fa fa-check" aria-hidden="true"></i> Long </small></span>
                            </div>
      
                                    <li class="list-group-item d-flex justify-content-between align-items-center main-gradient-tutorials mb-2"><a href="http://www.atnyla.com/overview-of-java-language/0/2"><i class="fa fa-code" aria-hidden="true"></i> Chapterwise Java Program</a></li>
                                <li class="list-group-item d-flex justify-content-between align-items-center main-gradient-tutorials mb-2"><a href="http://www.atnyla.com/fundamentals-of-c-language/1/20"><i class="fa fa-code" aria-hidden="true"></i> Chapterwise C Program</a></li>
                                <li class="list-group-item d-flex justify-content-between align-items-center main-gradient-tutorials mb-2"><a href="http://www.atnyla.com/array/3/54"><i class="fa fa-code" aria-hidden="true"></i> Chapterwise Data Structure Program</a></li>
                            </ul>
                      <br>
                      
                  
                   </div>
 </div>
 
</div>
 </div> 
 </div>
 </div>
 </div>
<button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
<style>
         
 #myBtn {
  display: none; /* Hidden by default */
  position: fixed; /* Fixed/sticky position */
  bottom: 20px; /* Place the button at the bottom of the page */
  right: 30px; /* Place the button 30px from the right */
  z-index: 99; /* Make sure it does not overlap */
  border: none; /* Remove borders */
  outline: none; /* Remove outline */
  background-color: blue; /* Set a background color */
  background-color: transparent;
  box-shadow: 0 6px 6px rgba(0, 0, 0, 0.6);
  color: white; /* Text color */
  cursor: pointer; /* Add a mouse pointer on hover */
  padding: 15px; /* Some padding */
  border-radius: 10px; /* Rounded corners */
  font-size: 18px; /* Increase font size */
  border-radius: 50%;
}

#myBtn:hover {
  background-color: #00a7f5; /* Add a dark-grey background on hover */
}
</style>
     
<script>
// Get the button:
let mybutton = document.getElementById("myBtn");

// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};

function scrollFunction() {
  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
    mybutton.style.display = "block";
  } else {
    mybutton.style.display = "none";
  }
}

// When the user clicks on the button, scroll to the top of the document
function topFunction() {
  document.body.scrollTop = 0; // For Safari
  document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
</script> 

<footer id="footer" style = "background: linear-gradient(to right, #1a2980, #26d0ce); margin-top: 10px;" class = "text-white p-3"> 
    <div class="footer-top">
      <div class="container-fluid">
        <div class="row"> 
          <div class="col-lg-2 col-md-6 footer-contact text-white"> 
          </div> 
          <div class="col-lg-3 col-md-6 footer-links text-white">
            <p style="font-size: 16px; color: white;">Useful Links</p>
            <ul>
              <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/" class = "text-white">Home</a></li>
              <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/about/" class = "text-white">About us</a></li> 
              <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/terms-and-conditions/" class = "text-white">Terms of service</a></li>
              <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/about/guest-post" class = "text-white">Guest Post</a></li> 
              <li><i class="bx bx-chevron-right"></i> <a href="hhttps://www.atnyla.com/about/ads/" class = "text-white">Advertisement</a></li>
            </ul>
          </div> 
          <div class="col-lg-3 col-md-6 footer-links text-white">
            <p style="font-size: 16px; color: white;">Login</p>
            <ul>
              <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/user/" class = "text-white">login</a></li>
              <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/user/" class = "text-white">Sign Up</a></li> 
            </ul>
          </div> 
          <div class="col-lg-3 col-md-6 footer-newsletter">
            <p style="font-size: 16px; color: white;">Visit All Home</p>
            <ul>
            <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/syllabus/java-programming-language/0" class = "text-white">Syllabus</a></li>
            <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/library/java-programming-language" class = "text-white">Subject</a></li>
            <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/library/" class = "text-white">Library</a></li>
            <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/gk-and-current-affairs" class = "text-white">GK/MCQ</a></li>
            <li><i class="bx bx-chevron-right"></i> <a href="https://www.atnyla.com/blog/" class = "text-white">Blog</a></li>
            <!--<p>Tamen quem nulla quae legam multos aute sint culpa legam noster magna</p>-->
            <!--<form action="" method="post">-->
            <!--  <input type="email" name="email"><input type="submit" value="Subscribe">-->
            <!--</form>-->
           </ul>
          </div> 
           <!--<div class="col-lg-2 col-md-6 footer-newsletter">-->
                <!-- <p style="font-size: 16px; color: white; ">Social Links</p>-->
                <!-- <ul> -->
                <!-- <li> <a href = "https://chat.whatsapp.com/BfdvA6k89H28bD4q4QqiaK" class="text-white">  Join Whatsapp Group  <i class="fa-brands fa-whatsapp"> </i> </a></li>-->
                <!--<li> <a href = "https://t.me/ComputerLanguageWithRumman" class="text-white">  Join Telegram Group  <i class="fa-brands fa-telegram"></i> </i> </a></li>-->
                <!--</ul>-->
            <!--</div>-->
        </div>
      </div>
    </div> 
    <div class="container d-md-flex   text-white"> 
      <div class="social-links text-center text-md-end pt-3 pt-md-0 text-white">
        <!--<a href="#" class="twitter"><i class="bx bxl-twitter"></i></a>-->
        <!--<a href="#" class="facebook"><i class="bx bxl-facebook"></i></a>-->
        <!--<a href="#" class="instagram"><i class="bx bxl-instagram"></i></a>-->
        <!--<a href="#" class="google-plus"><i class="bx bxl-skype"></i></a>-->
        <!--<a href="#" class="linkedin"><i class="bx bxl-linkedin"></i></a>-->
      </div>
    </div>
    
    <div class="me-md-auto text-center text-md-start">
        <div class="copyright text-center">
          © Copyright <strong><span>atnyla</span></strong>. All Rights Reserved
        </div>
        <div class="credits text-center"> 
          Designed by <a href="https://atnyla.com/"  style="color: white">atnyla.com</a>
        </div>
      </div> 
  </footer> 
    
<!-- Scripts -->
<!-- Bootstrap core JavaScript -->
<script src="https://atnyla.com/vendor/jquery/jquery.min.js"></script>

<script src="https://atnyla.com/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>  

<script src="https://atnyla.com/assets/js/isotope.min.js"></script>  

<!--<script src=" https://unpkg.com/isotope-layout@3.0.6/dist/isotope.pkgd.min.js"></script>  -->

<script src="https://atnyla.com/assets/js/owl-carousel.js"></script>
<!--<script src="https://atnyla.com/assets/js/lightbox.js"></script>-->
<script src="https://atnyla.com/assets/js/tabs.js"></script>

<!--<script src="https://atnyla.com/assets/js/video.js"></script>-->
<!--<script src="https://atnyla.com/assets/js/slick-slider.js"></script>--> 

<script src="https://atnyla.com/assets/js/custom.js"></script> 

<!--<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>-->
<!--<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?skin=desert"></script>-->

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> 
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> 
   
 
<script>
  //according to loftblog tut
  $(".nav li:first").addClass("active");

  var showSection = function showSection(section, isAnimate) {
    var direction = section.replace(/#/, ""),
      reqSection = $(".section").filter(
        '[data-section="' + direction + '"]'
      ),
      reqSectionPos = reqSection.offset().top - 0;

    if (isAnimate) {
      $("body, html").animate(
        {
          scrollTop: reqSectionPos,
        },
        800
      );
    } else {
      $("body, html").scrollTop(reqSectionPos);
    }
  };

  var checkSection = function checkSection() {
    $(".section").each(function () {
      var $this = $(this),
        topEdge = $this.offset().top - 80,
        bottomEdge = topEdge + $this.height(),
        wScroll = $(window).scrollTop();
      if (topEdge < wScroll && bottomEdge > wScroll) {
        var currentId = $this.data("section"),
          reqLink = $("a").filter("[href*=\\#" + currentId + "]");
        reqLink
          .closest("li")
          .addClass("active")
          .siblings()
          .removeClass("active");
      }
    });
  };

  $(".main-menu, .responsive-menu, .scroll-to-section").on(
    "click",
    "a",
    function (e) {
      e.preventDefault();
      showSection($(this).attr("href"), true);
    }
  );

  $(window).scroll(function () {
    checkSection();
  });
</script>
<script>
  $(document).ready(function () {
    $("#side-bar-toogle-btn").click(function () {
      $("#sidebar-list-group").toggle("slow");
    });
  });
</script> 
    
<script async src="https://fundingchoicesmessages.google.com/i/pub-7357847575760859?ers=1" nonce="P8qLHGFgH5IxNN3G6pLnUA"></script><script nonce="P8qLHGFgH5IxNN3G6pLnUA">(function() {function signalGooglefcPresent() {if (!window.frames['googlefcPresent']) {if (document.body) {const iframe = document.createElement('iframe'); iframe.style = 'width: 0; height: 0; border: none; z-index: -1000; left: -1000px; top: -1000px;'; iframe.style.display = 'none'; iframe.name = 'googlefcPresent'; document.body.appendChild(iframe);} else {setTimeout(signalGooglefcPresent, 0);}}}signalGooglefcPresent();})();</script>


<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<script>
// prettyPrint();
</script>
  
</body>
</html>