Added exists and length

This commit is contained in:
2016-02-17 12:22:17 +01:00
parent b8591ad2eb
commit e61b36fffe
3 changed files with 37 additions and 1 deletions
+31
View File
@@ -139,4 +139,35 @@ void clear()
printf("De gehele lijst in gecleared!\n");
}
int length()
{
int idx = 0;
struct node *p = pStart;
for (; NULL != p->next; p = p->next)
{
idx++;
}
return idx;
}
int exists(int data)
{
int idx = 0;
struct node *p = pStart;
for (; NULL != p->next; p = p->next)
{
if (p->data == data)
{
return idx;
}
idx++;
}
return -1;
}
+2 -1
View File
@@ -13,5 +13,6 @@ int add(int data, int begin);
int addPos(int data, int positie);
void show();
void clear();
int length();
int exists(int data);
#endif
+4
View File
@@ -42,6 +42,10 @@ int main()
printf("Showing data...\n");
show();
printf("Length of list: %d\n", length());
printf("Position of 22 in list: %d\n", exists(22));
printf("Position of 40 in list: %d\n", exists(40));
printf("Clearing data...\n");
clear();