If you need to push 'words' onto a stack of 'words' ...
you could use the ClistOfString.h file (and the other files it uses freely available there) to use a Clist of dynamic C strings to hold all the words you push_front
(You could use 'erase' to pop front
or add code to pop front.)
"I didn't start it yet i'm a beginer and we didn't learn stack yet at university so can you help me solving this exercise with explication thank you"
I just finished university and I know that they don't give assignments before teaching about the topic. David left you a good description(s) of how to go about this problem. The coding should be up to you, especially if this is an area that you wish to pursue. You should always strive to do your own homework, don't you think?
A stack is an abstract concept of, as @DavidW explained, that behaves in a first in, last out manner (or last in, first out if you prefer). To add an element to a stack, you "push" it onto the stack. Subsequent "push" operations will, conceptually, push the previous elements down one, and put the new element at the "top" of the stack. Then, when you "pop" an element off the stack, the last one "pushed" onto the stack will be returned, and the rest moved up one place. In C, this can be very expensive in terms of overhead, especially if the stack gets large. Usually we either use an array, where "push" puts the new element at the end, and the "pop" returns that element. As David mentioned, you can also use a linked list, which is more expensive in terms of memory, but very easy to implement. If you are using C++, the STL (standard template library) has a stack collection type that handles all of the gnarly stuff that has to go on.
So, using a stack to push the words of a sentence on, will reverse them as you pop them off at the end. IE, if you break up the sentence "This is a very good exercise in C programming" in to discrete words and push them onto a stack, as you pop them off and build a resulting string, what you would get would be "programming C in exercise good very a is This". Neat!
So, to close. We don't do your homework for you. We will help you fix your more egregious mistakes, and make suggestions when we think you should be able to handle the exercise on your own. Good luck, and post your code and problems when you have some.
Hi again @Rimaa21,
Have you ever heard about the concept of 'backtracking' ?
Suppose you were moving a robot about in some maze, and recording every step by pushing them onto a stack ... but you reach a dead end ... so now ... you can backtrack ... by popping the former moves from the stack, going in the opposite direction you did on the way in ... until you find some new passage way to try ... and then begin to push all those next forward moves onto the stack ... to be able tobacktrack again ...if needed.
Note also ...
that if your reverse a series of elements twice,
you will then get back the original order.
Until we see your complete original program specifications ...
and the code you have tried so far in your attempt to implement a solution ...
we are just best guesssing what your coding problem might be.