Announcements



Friday, April 2, 2004

Wednesday, Feb 15, 2004

Wednesday, Feb 4, 2004

Wednesday, Jan 28, 2004

Header File STACK.h

typedef int Item;
void STACKinit(int);
int STACKempty();
void STACKput(Item);
Item STACKpop();

Implementation File STACK.c

#include <stdlib.h>
#include "STACK.h"
static Item *s;
static int N;
void STACKinit(int maxN)
  { s = malloc(maxN*sizeof(Item)); N = 0; }
int STACKempty()
  { return N == 0; }
void STACKpush(Item item)
  { s[N++] = item; }
Item STACKpop()
  { return s[--N]; }

Client Program File CLIENT.c

#include <stdio.h>
#include <string.h>
#include "STACK.h"
main(int argc, char *argv[])
  { char *a = argv[1]; int i, N = strlen(a);
    STACKinit(N);
    for (i = 0; i < N; i++)
      {
        if (a[i] == '+')
          STACKpush(STACKpop()+STACKpop());
        if (a[i] == '*')
          STACKpush(STACKpop()*STACKpop());
        if ((a[i] >= '0') && (a[i] <= '9'))
          STACKpush(0);
        while ((a[i] >= '0') && (a[i] <= '9'))
          STACKpush(10*STACKpop() + (a[i++]-'0'));
      }
    printf("%d \n", STACKpop());

You will run as follows using "gcc" or "cc":

> gcc STACK.c CLIENT.c -o calc
(the "-o calc" tells the compiler to create the executable file named "calc" - if you omit this part, the compiler will create executable file "a.out")

Then you can run your program as follows:

> calc "5 6 *"   (answer is 30)

("5 6 *" part is needed because the input to the program is stored as a string in argv[1])

Hope this makes things easier.

Modnay, Jan 26, 2004

Wednesday, Jan 21, 2004



Friday, Jan 22, 2004 (Topic: HW1)

Linked List Exercise :

Q2.40 and Q2.43 for those who do not have a book (Q: Zhong Guo)

2.40 Solve the recurrence C(N) - C(N/2) + N^2 for N >= 2 C(1) = 0, and N is a power of 2 [In C(N), N is the subscript; N^2 means N to pwer 2)

2.43 Solve the recurrence C(N) - [C(N/2)]^2 for N >= 2 C(1) = 1, and N is a power of 2 [In C(N), N is the subscript)


Regarding what to implement (Q: Partha Ghosh)
   Submission

Wednesday, Jan 14, 2004