Stos

#include<iostream>
#include<conio.h>
using namespace std;

template <class T>
struct node
{
       node* prev;
       T     val;
};      

template <class T>
class Stack
{
	public:
		node<T> *top;   
		Stack();
		Stack(const Stack& A);
		~Stack();
		void   Push(T a);
		T      Pop();
		void   Show();     
		Stack<T>& operator+(T const & A);
};

template <class T> Stack<T>::Stack()
{ 	
	cout<<"Konstruktor\n";
	top=NULL;
}

template <class T> 
Stack<T>::Stack(const Stack& A)
{	cout<<"\nCopy:\n";
	top=NULL;
	node<T>* wsk=A.top;
	while(wsk)
	{
        this->Push(wsk->val);
        wsk=wsk->prev;
	}      
}

template <class T> Stack<T>::~Stack()
{
	cout<<"Destruktor\n";
	node<T> *wsk=top;
	node<T> *tmp;

	while(wsk)
	{
		tmp=wsk->prev;
		delete wsk;
		wsk=tmp;
    }
}

template <class T> void Stack<T>::Push(T a)
{ 
    node<T>* nowy=new node<T>;
	nowy->val=a;
	nowy->prev=NULL;
	if(!top)	top=nowy;
	else
	{
        node<T>* wsk=top;
 		while(wsk->prev)
		{
			wsk=wsk->prev;
		}
		nowy->prev=top;
		top=nowy;		 
	}
}

template <class T> 
Stack<T>& Stack<T>::operator+(T const & A)
{
         this->Push(A);
}

template <class T> T Stack<T>::Pop()
{
	node<T> *wsk=top;
	T		tmp;
	if(!top)	cout<<"Stos pusty\n";
	else
	{
		top=top->prev;
		tmp=wsk->val;
		delete wsk;
	}
	return tmp;
}

template <class T> void Stack<T>::Show()
{ 
    node<T>* wsk=top;
	if(!top) cout<<"Pusto...\n";
    else
    {	
        cout<<"Na Stosie: \n";
        while(wsk)
		{
			cout<<wsk->val<<"\n";
            wsk=wsk->prev;
		}
    }
}

int main()
{
    Stack<char> A;
    A.Push('a');  A.Push('b');     
    A.Push('c');  A.Show();

    Stack<float> B;
    B.Push(5.5);     B.Push(3.3);
    B.Push(4.4);     B.Show();
    cout<<"\nUsuwam ze Stosu: "<<B.Pop()<<endl;     
    cout<<"\n";      B.Show();

    Stack<char> C(A);
    C+('X');
    C.Show();

    getch();
    return 0;
}
Kategorie:Stos
  1. 17 Wrzesień 2012 o 7:33 pm

    When I originally left a comment I appear to have clicked the -Notify me when new comments are
    added- checkbox and from now on each time a comment is added I
    receive four emails with the exact same comment.

    Is there a way you are able to remove me from that service?
    Thank you!

  2. 17 Wrzesień 2012 o 8:10 pm

    You aren’t a follower of this blog, and from that account it’s your first comment, so I am don’t think you have that problem. If it’s true plz comment one more time, after that I’ll try to change options, but now I am don’t really sure that your coment isn’t only a spam, that aksimet don’t block. I’ll wait for a week, If you don’t say something I’ll delete yours comment.

  3. 1 Marzec 2014 o 2:43 pm

    Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is valuable and everything. But imagine if you added some great photos or videos to give
    your posts more, „pop”! Your content is excellent but
    with pics and videos, this blog could definitely be
    one of the best in its field. Amazing blog!

  4. 1 Marzec 2014 o 3:27 pm

    This information is worth everyone’s attention. Where can I find
    out more?

  5. 2 Marzec 2014 o 11:47 pm

    Heya i’m for the first time here. I came across this board and I in finding
    It really useful & it helped me out much. I’m hoping to give one thing back and help others
    such as you helped me.

  6. 5 Marzec 2014 o 1:24 am

    I am really impressed with your writing talents and also with the layout on your blog.
    Is this a paid subject matter or did you customize
    it your self? Either way stay up the nice high quaality writing, iit is uncommon to look a nice blog like this one
    nowadays..

  7. 6 Marzec 2014 o 12:42 pm

    I always used to study post in news papers but now as I
    am a user of web therefore from now I am using net for content, thanks to web.

  8. 3 Lipiec 2014 o 8:29 pm

    Thanks for finally wrriting about >Stoss | Czas na zeszyt…xD <Liked it!

  9. 4 Lipiec 2014 o 4:24 am

    Thanks for sharing your thoughts on winload.exe malware.
    Regards

  10. 9 Lipiec 2014 o 11:21 pm

    It’s an awesome piece of writing for all the internet viewers; they will get benefit from it I am sure.

  11. 9 Lipiec 2014 o 11:23 pm

    You really make it seem really easy along with your presentation but
    I in finding this matter to be actually something that
    I believe I would never understand. It sort of feels too
    complex and very vast for me. I’m looking ahead to your next publish, I’ll attempt to get the hold of it!

  12. 9 Lipiec 2014 o 11:23 pm

    Hello to every one, for the reason that I am actually eager
    of reading this blog’s post to be updated regularly. It consists of good data.

  13. 9 Lipiec 2014 o 11:24 pm

    Excellent website you have here but I was curious if you knew of any user discussion forums that
    cover the same topics discussed in this article?
    I’d really like to be a part of online community where
    I can get opinions from other experienced individuals
    that share the same interest. If you have any recommendations, please
    let me know. Bless you!

  14. 9 Lipiec 2014 o 11:26 pm

    WOW just what I was looking for. Came here by searching for usp10.dll crash

  15. 23 Lipiec 2014 o 5:08 am

    Link exchange is nothing else but it is just placing the other person’s weblog link
    on your page at proper place and other person will also do similar
    for you.

  16. 23 Lipiec 2014 o 5:42 am

    I’m really enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often.
    Did you hire out a developer to create your theme? Exceptional work!

  17. 23 Lipiec 2014 o 5:51 am

    I got this web site from my pal who informed me about this web page and at
    the moment this time I am browsing this web page and reading very informative posts at this place.

  18. 23 Lipiec 2014 o 6:13 am

    Hi everyone, it’s my first visit at this web page, and post is
    actually fruitful for me, keep up posting these types of articles or reviews.

  19. 23 Lipiec 2014 o 6:44 am

    We are a gaggle of volunteers and opening a new scheme in our community.
    Your site offered us with helpful information to work on. You’ve
    done a formidable process and our whole neighborhood shall be grateful to you.

  20. 23 Lipiec 2014 o 6:46 am

    Excellent blog! Do you have any suggestions for aspiring writers?
    I’m planning to start my own site soon but I’m a little lost on everything.
    Would you propose starting with a free platform like WordPress or go
    for a paid option? There are so many options out there that I’m completely confused ..

    Any tips? Kudos!

  21. 23 Lipiec 2014 o 6:38 pm

    This is my first time pay a quick visit at here and i am genuinely impressed to read all at one
    place.

  22. 24 Lipiec 2014 o 4:28 pm

    With havin so much content and articles do you ever run into
    any problems of plagorism or copyright violation? My blog has a lot of unique
    content I’ve either written myself or outsourced but it appears
    a lot of it is popping it up all over the web without my agreement.
    Do you know any methods to help stop content from being stolen? I’d certainly appreciate it.

  23. 24 Lipiec 2014 o 4:29 pm

    Do you mind if I quote a couple of your articles as long as I provide
    credit and sources back to your weblog? My
    blog site is in the exact same niche as yours and my visitors would definitely benefit from some of the information you provide here.
    Please let me know if this okay with you. Thanks a lot!

  24. 22 Sierpień 2014 o 12:43 pm

    Hi, I wish for to subscribe for this webpage to take most recent updates, therefore where can i do it
    please assist.

  25. 27 Sierpień 2014 o 9:06 pm

    Thank you for the auspicious writeup. It in truth was a enjoyment account it.
    Glance complicated to more added agreeable from you!
    However, how can we keep up a correspondence?

  26. 10 Wrzesień 2014 o 1:18 am

    If you are going for best contents like me, just go to see this web page every day as it presents feature contents, thanks

  27. 14 Wrzesień 2014 o 7:05 am

    Thanks to my father who stated to me on the topic of this weblog, this website is actually amazing.

  28. 19 Wrzesień 2014 o 12:32 pm

    Wow, that’s wat I waas exploring for, what a information! existing here at
    thhis weblog, thanks admin of this webb page.

  29. 26 Wrzesień 2014 o 11:33 pm

    Hey would you mind letting me know which hosting company you’re using?
    I’ve loaded your blog in 3 different internet browsers and I
    must say this blog loads a lot quicker then most. Can you recommend a good hosting provider
    at a honest price? Many thanks, I appreciate it!

  30. 27 Wrzesień 2014 o 7:30 pm

    I just like the helpful information you provide for your articles.

    I will bookmark your blog and take a look at once more right here regularly.
    I’m relatively sure I’ll learn plenty of new stuff proper right here!

    Best of luck for the next!

  31. 6 Październik 2014 o 9:39 pm

    Everyone loves it when folks come together and share views.
    Greawt site, tick with it!

  1. 24 Marzec 2015 o 10:17 am

Skomentuj

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Log Out / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Log Out / Zmień )

Facebook photo

Komentujesz korzystając z konta Facebook. Log Out / Zmień )

Google+ photo

Komentujesz korzystając z konta Google+. Log Out / Zmień )

Connecting to %s

%d bloggers like this: