473,597 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help me ....implementin g multiple stacks using arrray

5 New Member
i want to implement multiple stacks using arrays..I am able to create ,insert and print them but not poping an element form any of the stack..This is what i have
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int top[5];
  4. int bot[5];
  5.  
  6.  
  7. void main()
  8. {
  9. int a[50]={0} ;
  10. int length,num;
  11. int ch;
  12. int temp,x,st_no,st_no1;
  13. int b,i,j,k;
  14. clrscr();
  15. printf("Enter the length of the total stack: ");
  16. scanf("%d",&length);
  17. printf("\nEnter the number of stacks: ");
  18. scanf("%d",&num);
  19. //divinding the arrays into stacks
  20. b=(length)/(num);
  21. top[0]=0;
  22. bot[0]=0;
  23. for(i=1;i<num;i++)
  24.   {
  25.     top[i]=top[i-1]+b;
  26.     bot[i]=bot[i-1]+b;
  27.   }
  28. do
  29.    {
  30.     printf("\n1.PUSH 2.POP 3.PRINT 4.EXIT \n");
  31.     printf("Enter the choice: ");
  32.     scanf("%d",&ch);
  33.     switch(ch)
  34.       {
  35.        case 1:
  36.     printf("Enter the stack number: ");
  37.     scanf("%d",&st_no);
  38.     if(top[st_no-1]==bot[st_no] || top[st_no-1]==length)
  39.     printf("\n\n\n!!THE %d STACK IS FULL\n",st_no);
  40.     else
  41.     {
  42.       printf("ENTER THE ELEMENT TO BE PUSHED");
  43.       scanf("%d",&x);
  44.       a[top[st_no-1]]=x;
  45.      top[st_no-1]=top[st_no-1]+1;
  46.     }
  47.  
  48.  
  49.       break;
  50.     //-------------------------------------------------------
  51.     case 2:
  52.         printf("\nENTER THE STACK NUMBER");
  53.         scanf("%d",&st_no1);
  54.         printf("\nThe stack you have choosen is %d",st_no1-1);
  55.         printf("-----%d-----",a[top[(st_no-1)]]);
  56.         if(top[st_no-1]==bot[st_no-1])
  57.         printf("\n!STACK EMPTY!\n");
  58.         else
  59.         {
  60.  
  61.           printf("\nDELETED ELMENT IS: %d\n",a[top[st_no1-1]]);
  62.           top[st_no1-1]=top[st_no1-1]-1;
  63.            }
  64.  
  65.          break;
  66.        //----------------------------------------------------------
  67.     case 3:
  68.        k=0;
  69.        for(i=0;i<num;i++)
  70.         {
  71.         printf("\nThe elements in stack %d are: ",i+1);
  72.  
  73.                for(j=0;j<b;j++)
  74.          {
  75.           printf("%d->",a[i+j+k]);
  76.           }
  77.            k=k+b-1;
  78.          }
  79.  
  80.  
  81.         break;
  82.     }
  83.     }
  84.     while(ch<4);
  85.     getch();
  86.  
  87. }
  88.  
Oct 15 '06 #1
0 2325

Sign in to post your reply or Sign up for a free account.

Similar topics

7
4824
by: Gabriele Farina | last post by:
Hi, I'd like to manage multiple socket connection without having to use Threads. I'd like to manage every connection when it is returned from socket_Accept(), without having to wait for the current running tonnection to stop. How can I do that? bye
4
6200
by: Madhu Gopinathan | last post by:
Hi All, I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor. Each task is processed in a separate thread. Each of the executer threads is an STA thread, and it goes ahead and executes the task. No problems are encountered when tasks are executed one at a time, but when multiple tasks are executed...
10
2119
by: Rich Kucera | last post by:
Holding all versions at 5.0.4, Multiple stacks with multiple-version configurations inevitable Will have to wait to see what the impact of problems such as http://bugs.php.net/bug.php?id=33643 to the application world. We may wait for a suitable popular resolution and jump to that version in the future. There's already a rift between PHP4 and PHP5, and then further developments such as these create another, splitting the camp into 4....
4
5480
by: andy.mcvicker | last post by:
Hi Gang I have a large VB program that at one point does a lookup to a small table (26 rows by 3 columns). With this table I have to do some counting and retrieval of data. I'm finding that this slows the program right down. Is there any way I can take a copy of the table in memory and access it there. Perhaps a cursor or something? Can someone help with a code sample. Here's my code to do the lookup.
4
3316
by: phl | last post by:
hi, My question is: 1. To avoid possible memory leaks, when you use this pattern, after you have dealth with the unmanaged resources and before you take your object off the finalize queue, how are you sure that your managed object resources are completely freed up of resources it's might be using? In my case below I have a private bool variable. Are there any other managed resource that you might need to explicitly free up in
2
4574
by: Daniel | last post by:
Hi, I have a question regarding the memory managment in stl stacks. I want to use stacks to store a very large amount of numbers (some millions), thus I'm interested in how the stack behaves when it has to increase its memory. http://www.sgi.com/tech/stl/stack.html, the stacks default underlying container is a deque that has amortized constant time insertion and removal of elements.
5
2003
by: satan | last post by:
I need a help in my method equalStack in my class StackClass. public class StackClass { private int maxStackSize; //variable to store the maximum //stack size private int stackTop; //variable to point to the top //of the stack private DataElement list; //array of reference variables
6
3977
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public string UID; public string PWD; }
19
6323
by: Zytan | last post by:
I want multiple instances of the same .exe to run and share the same data. I know they all can access the same file at the same time, no problem, but I'd like to have this data in RAM, which they can all access. It seems like a needless waste of memory to make them all maintain their own copy of the same data in RAM at the same time. What's the best way to achieve this? I've heard of memory mapped files, so maybe that's the answer. ...
0
7969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8035
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.