Results 1 to 5 of 5
  1. #1

    Default need help for push and pop in C prog


    #include<stdio.h>
    #include<conio.h>
    #define MAXSTACK 10

    int items[MAXSTACK];

    int ctr=0;


    void push(int item){

    items[ctr] = item;
    ctr++;
    }
    int pop(){
    return items[--ctr];

    }
    void modify(){
    int i;
    for(i=0; i<MAXSTACK; i++){
    if(items[i]%2==0){
    items[i] = items[i]/2;
    }else {
    items[i] = items[i]*3+1;
    }
    }

    }
    void displayStack(){
    int i;
    for(i=MAXSTACK; i>=0; i--){
    if(items[i]!=0){
    printf("%-5d",items[i]);
    }

    }
    }


    int main(){

    int i,item;

    printf("Enter values to stack(10): \n");
    for(i=0; i<MAXSTACK; i++){
    scanf("%d",&item);
    push(item);
    }

    printf("Original Stack elements:\n");
    displayStack();
    modify();
    printf("\nModified Stack Elements: \n");
    displayStack();
    printf("\npop():%d",pop());
    printf("\npop():%d",pop());
    printf("\npop():%d",pop());
    getch();

    }



    Implement this:

    S.push(10);
    S.push(5);
    S.pop();
    S.top();
    S.push(6);
    S.top();

  2. #2

    Default Re: need help for push and pop in C prog

    please anyone?? need for assignment

  3. #3

    Default Re: need help for push and pop in C prog

    please read use the tag 'code'

    para mas dali basahon

  4. #4

    Default Re: need help for push and pop in C prog

    Quote Originally Posted by koujie View Post
    please anyone?? need for assignment
    then go to

    https://www.istorya.net/forums/assignments

    not here https://www.istorya.net/forums/programming

  5. #5

    Default Re: need help for push and pop in C prog

    Quote Originally Posted by koujie View Post
    Implement this:

    S.push(10);
    S.push(5);
    S.pop();
    S.top();
    S.push(6);
    S.top();
    huh? Pwede diay na? You're using C language right? not C++? It looks to me, that you're teacher wants to implement it in OOP.

  6.    Advertisement

Similar Threads

 
  1. Replies: 46
    Last Post: 06-20-2013, 03:58 AM
  2. Replies: 5
    Last Post: 03-04-2013, 04:24 PM
  3. Need help for affordable baptism reception in Fuente area
    By farrah82 in forum Parties & Events
    Replies: 2
    Last Post: 03-13-2012, 01:49 AM
  4. need help for our trip in bohol
    By yujjieo in forum Destinations
    Replies: 10
    Last Post: 01-06-2011, 04:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top