lec 1
and other things this is mad confusing
This commit is contained in:
commit
045d7367a8
11 files changed
+349
No files matched your search
@@ -0,0 +1,109 @@
|
||||
// for printf
|
||||
#include <stdio.h>
|
||||
#include "arraylist.h"
|
||||
// stack list
|
||||
void ldalistinit(ldaArrayList *l)
|
||||
{
|
||||
l->size = 0;
|
||||
}
|
||||
|
||||
int ldalistlen(ldaArrayList *l)
|
||||
{
|
||||
return l->size;
|
||||
}
|
||||
int ldalistcheck(ldaArrayList *l)
|
||||
{
|
||||
if (ldalistlen(l) >= 100)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ldalistpush(ldaArrayList *l, int value)
|
||||
{
|
||||
if (ldalistcheck(l) != 0)
|
||||
return -1;
|
||||
|
||||
l->list[l->size++] = value;
|
||||
return 0;
|
||||
}
|
||||
int ldalistadd(ldaArrayList *l, int at, int value)
|
||||
{
|
||||
if (ldalistcheck(l) != 0)
|
||||
return -1;
|
||||
|
||||
int size = ldalistlen(l);
|
||||
if (at > size)
|
||||
return -1;
|
||||
else if (at == size)
|
||||
{
|
||||
return ldalistpush(l, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = size; i > at; i--)
|
||||
{
|
||||
l->list[i] = l->list[i - 1];
|
||||
};
|
||||
l->list[at] = value;
|
||||
l->size += 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ldalistpop(ldaArrayList *l, int *put_here)
|
||||
{
|
||||
if (ldalistlen(l) <= 0)
|
||||
return -1;
|
||||
*put_here = l->list[l->size--];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ldalistremove(ldaArrayList *l, int at, int *put_here)
|
||||
{
|
||||
if (ldalistlen(l) <= 0)
|
||||
return -1;
|
||||
|
||||
int size = ldalistlen(l);
|
||||
if (at > size)
|
||||
return -1;
|
||||
else if (at == size)
|
||||
{
|
||||
return ldalistpop(l, put_here);
|
||||
}
|
||||
else
|
||||
{
|
||||
*put_here = l->list[at];
|
||||
for (int i = at; i++ > size;)
|
||||
{
|
||||
l->list[i] = l->list[i - 1];
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ldalistlookup(ldaArrayList *l, int at, int *copy_here)
|
||||
{
|
||||
if (at > ldalistlen(l))
|
||||
return -1;
|
||||
*copy_here = l->list[at];
|
||||
return 0;
|
||||
}
|
||||
void ldalistprint(ldaArrayList *l)
|
||||
{
|
||||
printf("[");
|
||||
for (int i = 0,
|
||||
cur,
|
||||
_ = ldalistlookup(l, i, &cur) || printf("%d", cur);
|
||||
++i < ldalistlen(l) && printf(", ");
|
||||
_ = ldalistlookup(l, i, &cur) || printf("%d", cur))
|
||||
;
|
||||
printf("]");
|
||||
};
|
||||
|
||||
// int main(int argc, char const *argv[])
|
||||
// {
|
||||
// /* code */
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// for printf
|
||||
// stack list
|
||||
|
||||
|
||||
#ifndef COMMON_LDAARRAYLIST_H
|
||||
#define COMMON_LDAARRAYLIST_H
|
||||
typedef struct LdaArrayList
|
||||
{
|
||||
int size;
|
||||
int list[100];
|
||||
} ldaArrayList;
|
||||
|
||||
void ldalistinit(ldaArrayList *l);
|
||||
int ldalistlen(ldaArrayList *l);
|
||||
int ldalistcheck(ldaArrayList *l);
|
||||
int ldalistpush(ldaArrayList *l, int value);
|
||||
int ldalistadd(ldaArrayList *l, int at, int value);
|
||||
int ldalistpop(ldaArrayList *l, int *put_here);
|
||||
int ldalistremove(ldaArrayList *l, int at, int *put_here);
|
||||
|
||||
int ldalistlookup(ldaArrayList *l, int at, int *copy_here);
|
||||
|
||||
void ldalistprint(ldaArrayList *l);
|
||||
#endif
|
||||
Reference in new issue
Block a user