473,811 Members | 3,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data Structure in C

you can construct stack in easy way in C as following
#include<stdio. h>
# define MaxStack 10
int top=0;
void clearstack(int stack[MaxStack]);
int emptystack(int stack[MaxStack]);
int fullstack(int stack[MaxStack]);
void pushstack(int stack[MaxStack],int newelements);
void popstack(int stack[MaxStack],int *element);

void main()
{
int x,i,stack[MaxStack];
clearstack(stac k);
for(i=0;i<MaxSt ack;i++)
{scanf("%d",&x) ;
pushstack(stack ,x);
}
for(i=0;i<MaxSt ack;i++)
{
apopstack(stack ,&x);
printf("%d\n",x );
}

}
void clearstack(int stack[MaxStack])
{
stack[top]=0;
return;
}
int emptystack(int stack[MaxStack])
{return (stack[top]==0);
}
int fullstack(int stack[MaxStack])
{
return (stack[top]==MaxStack)
;
}

void pushstack(int stack[MaxStack],int newelement)
{
stack[top]=stack[top]+1;
stack[stack[top]]=newelement;
}
popstack(int stack[MaxStack],int *element)
{
*element =stack[stack[top]];
stack [top]=stack[top]-1;
}

Mar 1 '06 #1
3 1786
# include said:
you can construct stack in easy way in C as following
#include<stdio. h>
# define MaxStack 10
int top=0;
void clearstack(int stack[MaxStack]);
int emptystack(int stack[MaxStack]);
int fullstack(int stack[MaxStack]);
void pushstack(int stack[MaxStack],int newelements);
void popstack(int stack[MaxStack],int *element);

void main()


At this point, you reveal your ignorance of C. I see little point in looking
through the rest of your code. You need a better C book.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 1 '06 #2
# include wrote:
you can construct stack in easy way in C as following
#include<stdio. h>
# define MaxStack 10
int top=0;
void clearstack(int stack[MaxStack]);
int emptystack(int stack[MaxStack]);
int fullstack(int stack[MaxStack]);
void pushstack(int stack[MaxStack],int newelements);
void popstack(int stack[MaxStack],int *element);

void main()
{
int x,i,stack[MaxStack];
clearstack(stac k);
for(i=0;i<MaxSt ack;i++)
{scanf("%d",&x) ;
pushstack(stack ,x);
}


<snip code snippet>

Why have you pasted this program ? Is there something wrong in it that
you want someone to help you or you just want a confirmation from us ?

BTW, main() **should** only return int. Your program may compile but
it is bound to give undefined behavior since your main is returning
void.

Thats the reason for the post by Richard.

Mar 2 '06 #3
"# include" <wa*********@ya hoo.com> writes:
you can construct stack in easy way in C as following
#include<stdio. h>
# define MaxStack 10
It's conventional (but not required) to use all-caps for macro names:

#define MAXSTACK 10
int top=0;
void clearstack(int stack[MaxStack]);
int emptystack(int stack[MaxStack]);
int fullstack(int stack[MaxStack]);
void pushstack(int stack[MaxStack],int newelements);
void popstack(int stack[MaxStack],int *element);
MaxStack in each of these function declarations is silently ignored.
The first argument of each of these functions is really an int*.

void main()
No, main() returns int.
{
int x,i,stack[MaxStack];
clearstack(stac k);
for(i=0;i<MaxSt ack;i++)
{scanf("%d",&x) ;
pushstack(stack ,x);
}
for(i=0;i<MaxSt ack;i++)
{
apopstack(stack ,&x);
printf("%d\n",x );
}

[snip]

Your code is very difficult to read. Proper use of indentation and
whitespace would help tremendously. There may be problems beyond what
I've pointed out, but it's not worth the pain of reading your code to
find them.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2108
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 fields. I did this by making the following type of data...
3
2379
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 structure and then removes them as described below.
2
6469
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_ { char szInput; char szOutput; int iSum;
11
3195
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 accomplish it. For example: int main void() { while there are more data types { print next data type; }
5
4808
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. "payload") using pointers. Examples of these are binary trees, hash tables etc. Thus, the message itself contains only a pointer to the actual data. When the message is sent to the same processor, these pointers point to the original locations, which...
3
8904
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 End Structure
11
4148
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 the actual structure itself. Is this true of C# also?
3
2169
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. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475158 wy ------------------------------------------------------------------------
29
4276
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
3410
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 commits it. How does the other user get the updated view without polling for changes? Is there some sort of callback mechanism that can be set up on the dataset or connection? TIA
0
9724
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
10644
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
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...
0
10127
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7665
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
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4336
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
3
3015
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.