Informações

Autores Lamarana Balde Anthony Doeraene
Prazo de entrega Sem prazo
Limite de submissão No limitation

Etiquetas

Entrar

Stack

You have to write a function called push that add integers to a Stack according to the LIFO principle. You have then to code a function which sort the integer Stack in ascending order.

The stack is defined by this structure:

struct stack {
    int data;
    struct stack* next;
};

Examples of push :

  • push(s,3)
  • push(s,49)
  • push(s,-3)

After these calls, the stack contains [-3,49,3]

Hint : You can implement auxiliary functions (ex : pop, insert, empty, ...) to make the implementation easier.


Questão 1: Push
/*
 *@pre x is an int, s can be NULL
 *@post add this item to the stack
 *@ret 0 if no error, -1 if malloc fails
 */
int push(struct stack** s, int x);
Questão 2: Sort
/*
 *@pre s==NULL or s!=NULL ,
 *@post sort the existing stack in place, does nothing if s==NULL
 */

void sortStack(struct stack** s)
Questão 3: Fonctions auxiliaires

Ecrivez ici vos fonctions auxiliaires