473,241 Members | 1,546 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,241 software developers and data experts.

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(stack);
for(i=0;i<MaxStack;i++)
{scanf("%d",&x);
pushstack(stack,x);
}
for(i=0;i<MaxStack;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 1768
# 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(stack);
for(i=0;i<MaxStack;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*********@yahoo.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(stack);
for(i=0;i<MaxStack;i++)
{scanf("%d",&x);
pushstack(stack,x);
}
for(i=0;i<MaxStack;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_Keith) 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
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: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.