#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    [Help] Simple stack and queue implementation


    Good day programmers..
    Im new in programming field.. I badly need your help with Stack implementation as well as Queue..

    Could you please give me a complete source code of simple Stack implementation and Queue implementation in C ?
    Please dont combine the two in one program.. I need a separate program for the two..

    I hope you'll help me and provide me source code..

    I just need to study in advance because stack and queue will be our topic for the next two weeks. I hope you understand me. I want to study in advance for the benefit of mine.
    Thank you so much. . Thank you.

    By the way, im using DevC++..
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,387
    Rep Power
    1871
    No, this isn't a free homework service
    http://forums.devshed.com/c-programm...st-259106.html

    > I just need to study in advance because stack and queue will be our topic for the next two weeks.
    Fine - see you in two weeks when you've studied, and then attempted your homework.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0
    Ok sir. Sorry and thank you. :-(
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0
    This is my partial code for queue. . I dont know if its correct coz i havent compile and run it yet. Could you please check?

    main ()
    {
    int tail=0,out;
    int i,num,my_queue[size]
    char ans;
    For (i=0,i<size;i++)
    {
    printf("enter num:")
    scanf("%d",&num)

    if (tail<size)
    {
    my_queue[tail]=num;
    tail++;
    }
    else{ printf ("full"); }
    }
    do{
    printf("d0 u want t0 dequeue <y/n>:");
    scanf("%c",&ans);
    if(ans=='y'){
    out=my_queue[tail--];
    printf("dequeued:%d",out);
    }
    }while(ans =='y');

    getch();
    return 0;
    }

    Comments on this post

    • DaWei_M disagrees : For "I havent compile and run it yet."
    • ptr2void disagrees : See post below
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    89
    Rep Power
    135
    Originally Posted by 020889
    .. i havent compile and run it yet. Could you please check?
    Why haven't you compiled and ran it yet? The compiler will check to see if your code is valid and will give you errors if it isn't. Also, when posting code please use code tags and indentation helps:

    Code:
    int main ()
    {
    	int tail=0,out;
    	int result = 0; // for scanf
    	int i,num,my_queue[size]
    	char ans;
    	for (i=0,i<size;i++)
    	{
    		printf("enter num:")
    		scanf("%d",&num)
    
    		if (tail<size)
    		{
    			my_queue[tail]=num;
    			tail++;
    		}
    		else
    		{ 
    			printf ("full"); 
    		}
    	}
    	do{
    		printf("d0 u want t0 dequeue <y/n>:");
    		/* always check what scanf returns, it should return the number of variables read in*/
    
    		result = scanf("%c",&ans);
    		if(result != 1)
    		{
    			//..handle error here, scanf should of returned one
    		}
    		if(ans=='y')
    		{
    			out=my_queue[tail--];
    			printf("dequeued:%d",out);
    		}
    	}while(ans =='y');
    
    	getch();
    
    return 0;
    }
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0
    Okey sir. Thank you. I forgot to use tags and/or indentions..sorry. I will modify my program later. Thanks.
  12. #7
  13. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    Our Filipino friend apparently got the code here.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  14. #8
  15. No Profile Picture
    ......@.........
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2004
    Posts
    1,345
    Rep Power
    56
    FWIW - there is a related group of sites - mathoverflow.com as an example - that allow senior users to effectively police threads like these. Rather than the having moderators step in.

    At any rate the junk post factor here needs improvement. IMO. The serious posters here really try hard to clean things up. This thread should have been locked long before I was able to post this rant.

    -- Long time lurker

    Comments on this post

    • ridv34 agrees : Best post/idea this year...
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    149
    Rep Power
    37
    Any textbook worth it's salt should have those implementations that you want. I know you want C implementation, but for C++ try Data Structures & Other Objects Using C++ by Main and Savitch.

IMN logo majestic logo threadwatch logo seochat tools logo