473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Data Structure

5
Kindly help me with these problems ..
*sigh* I'm having a hard time for this ..

C Programming please ..

Problem 1 : Create a program to test the package for the ADT stack
INPUT : Commands entered by the user
OUTPUT : List of commands and messages describing the effects of each command.

SAMPLE OUTPUT :
Use the ff. commands to test the ADT Stack .
C - Create a stack
D - Dump the stack
E - Test whether the stack is empty
F - Check if operation failed ( show StackError )
H - Prints the list of commands
PO - Pop an element of the stack
PU - Push an item onto the stack
Q - Quit Testing

Command : C
-> Stack Created

Command : E
-> Stack Empty? True

- - - - - - - - - - - - - - - -

Problem 2 : Create a program that will output a base-ten representation to a base two representation using stack data structure.

I need your help people .. T_T
Jul 8 '07 #1
4 1600
weaknessforcats
9,208 Expert Mod 8TB
What do you have so far?

I can help you if you are stuck in your code but I cannot provide a complete solution.
Jul 8 '07 #2
ch13f
5
What do you have so far?

I can help you if you are stuck in your code but I cannot provide a complete solution.
#include<stdio.h>
main()
{
int x,y,num,i;
int ans[500];
clrscr();
printf("Enter number:");
scanf("%d",&num);
x=num%2;
y=num/2;
i=0;
while(y){
if(!x)
ans[i]=x;
x=x%2;
y=y/2;
i++;
}
for(i;i>=0;i--) printf("%d", ans[i]);
getch();
}

that's for the #2 ..
but It seems that it doesn't give the correct output .. :)
Jul 9 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
An array is not a good choice for a stack.

You need a linked list.

You "push" a number onto the top of the stack by adding it to the end of the list.
You "pop" a number by removing ti from the end of the list.
You dump the stack by reading the list from bback to front
etc...

OR

You "push" a number onto the top of the stack by adding as the first element of the list.
You "pop" a number by removing itfrom the front of the list.
You dump the stack by reading the list from front to back
etc...

It doesn't matter which way you choose as long as the last number "pushed" is the next one "popped".
Jul 9 '07 #4
seforo
60
Search google on how to create a stack data structure, that will be a very good start
Jul 9 '07 #5

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

Similar topics

1
by: dmb000006 | last post by:
Hello, I have a database style data structure, each record has several fields. I would like to create a nested data structure that would let me 'query' the data on the value of certain...
3
by: Mike Jones | last post by:
need help with data structures.Looking for ways to start, sample code, anything Program description: Design and implement a Visual C++ .NET program that inserts values into a data...
2
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
11
by: theshowmecanuck | last post by:
As a matter of academic interest only, is there a way to programmatically list the 'c' data types? I am not looking for detail, just if it is possible, and what function could be used to...
5
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e....
3
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String...
11
by: Macca | last post by:
Hi, I'm writing an application that will pass a large amount of data between classes/functions. In C++ it was more efficient to send a pointer to the object, e.g structure rather than passing...
3
by: aurora | last post by:
This is an entry I just added to ASPN. It is a somewhat novel technique I have employed quite successfully in my code. I repost it here for more explosure and discussions. ...
29
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.