Thread: stack

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    3

    stack

    Hello.....i had a question in mind.....

    i have built a simple stack with push and pop....i used a link list implemntation.......it works fine wen i say push 5 it pushes int 5 in the stack

    now wat im trying to get to is.... is it possible to push more than 1 number in at the sametime like for example

    push 2 3 5 6 8

    how cod i ge the program to read after the 2 ....do i need a tokenizer ??

    thanks

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You could pass in an array of ints, or you should make push a variadic function. Actually, that last one might not be a bad idea, although variadic functions are usually discouraged.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    3

    hello

    thanks for the reply

    what is a varidic function my push looks like this
    Code:
    int Push (void *it) {
    	// new node i to be the top node.
    	node *i;
    	i = (node*)malloc(sizeof(node));
    	// set its data
    	i->data = (item*)it;
    	// Link i to top
    	i->next = top;
    	// make i the top.
    	top = i;
    	return 0;
    }
    and how wod i pass in an array of ints ....

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    3

    hello

    like if i say push 3 4 5 6 ......how cod i get that to be saved into an array....

  5. #5

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > how cod i ge the program to read after the 2 ....do i need a tokenizer ??
    Yes, you parse the line to extract each number in turn, then call your push function with each result.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  2. infix evaluation using stack
    By lewissi in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2005, 02:56 AM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM