Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct linie{
- struct linie *prev;
- char data;
- struct linie *next;
- }linie;
- typedef linie* Linie;
- typedef struct text{
- struct text *prev;
- Linie data;
- struct text *next;
- }text;
- typedef text* Text;
- typedef struct _backup{
- Text* data;
- int capacity;
- int size;
- }* Backup;
- Backup initBackup()
- {
- Backup nou;
- nou = (Backup) malloc(sizeof(struct _backup));
- nou->capacity = 10;
- nou->data = (Text *) malloc(nou->capacity*sizeof(Text));
- nou->size = 0;
- return nou;
- }
- void ensureCapacity(Backup s, int minCapacity)
- {
- if(s->capacity < minCapacity)
- {
- s->data = (Text*) realloc(s->data, minCapacity*sizeof(Text));
- s->capacity = minCapacity;
- }
- }
- Text top(Backup s)
- {
- if(s->size == 0)
- {
- return NULL;
- }
- else
- {
- return s->data[s->size-1];
- }
- }
- /** 7. Intoarce elementul din varful stivei si il elimina din stiva. Intoarce 0 daca stiva e goala */
- Text pop(Backup s)
- {
- Text c;
- if(s->size == 0)
- {
- return NULL;
- }
- else
- {
- c = s->data[s->size-1];
- s->size--;
- return c;
- }
- }
- void push(Backup s, Text value)
- {
- Text nou, tmp;
- tmp = value;
- if(tmp != NULL)
- {
- nou = initText(tmp->data);
- while(tmp->next != NULL)
- {
- tmp = tmp->next;
- nou = addLast2(nou, tmp->data);
- }
- if(s->size < s->capacity)
- {
- s->data[s->size] = nou;
- s->size++;
- }
- else
- {
- ensureCapacity(s, 2*s->size);
- s->data[s->size] = nou;
- s->size++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment