S
Steffen Loringer
Hi all,
I'm using a linked list (double). The program is growing(windows xp task
manager) if the showAllListNodes function is activated. But I can't
figure out why. Any ideas???
Thanks
Steven
my code is as follows:
#include <stdio.h>
#include <stdlib.h>
typedef struct ListNode
{
int value;
struct ListNode *previous;
struct ListNode *next;
};
void newListNode(struct ListNode *temp_ls,int value);
void showAllListNodes(void);
void addListNode(int value);
void removeLastListNode(void);
struct ListNode *first_ls_ ;
struct ListNode *last_ls_ ;
int malloc_calls;
int free_calls;
void main(void)
{
int c = 1000;
int i = 13;
int x = 0;
first_ls_= malloc(sizeof(struct ListNode));
first_ls_->previous = NULL;
first_ls_->value = 0;
first_ls_->next = NULL;
last_ls_ = first_ls_;
first_ls_->next = last_ls_;
for (x=0;x<99000;x++)
{
for (i=0;i<c;i++)
{
addListNode(i+1);
}
showAllListNodes();
for (i=0;i<c;i++)
{
removeLastListNode();
}
}
printf("\n Malloc Calls = %d \n",malloc_calls);
printf("\n Free Calls = %d \n",free_calls);
}
void showAllListNodes()
{
struct ListNode *temp_ls = malloc(sizeof(struct ListNode));
malloc_calls++;
temp_ls = first_ls_;
while(temp_ls != NULL)
{
//printf("\n %d =%d= %d
Value=%d\n",temp_ls->previous,temp_ls,temp_ls->next,temp_ls->value);
temp_ls = temp_ls->next;
}
free(temp_ls);
free_calls++;
}
void addListNode(int value)
{
struct ListNode *temp_ls = malloc(sizeof(struct ListNode));
malloc_calls++;
temp_ls->previous = NULL;
temp_ls->value = value;
temp_ls->next = NULL;
temp_ls->previous = last_ls_;
last_ls_->next = temp_ls;
last_ls_ = temp_ls;
}
void removeLastListNode(void)
{
last_ls_ = last_ls_->previous;
free(last_ls_->next);
free_calls++;
last_ls_->next = NULL;
}
I'm using a linked list (double). The program is growing(windows xp task
manager) if the showAllListNodes function is activated. But I can't
figure out why. Any ideas???
Thanks
Steven
my code is as follows:
#include <stdio.h>
#include <stdlib.h>
typedef struct ListNode
{
int value;
struct ListNode *previous;
struct ListNode *next;
};
void newListNode(struct ListNode *temp_ls,int value);
void showAllListNodes(void);
void addListNode(int value);
void removeLastListNode(void);
struct ListNode *first_ls_ ;
struct ListNode *last_ls_ ;
int malloc_calls;
int free_calls;
void main(void)
{
int c = 1000;
int i = 13;
int x = 0;
first_ls_= malloc(sizeof(struct ListNode));
first_ls_->previous = NULL;
first_ls_->value = 0;
first_ls_->next = NULL;
last_ls_ = first_ls_;
first_ls_->next = last_ls_;
for (x=0;x<99000;x++)
{
for (i=0;i<c;i++)
{
addListNode(i+1);
}
showAllListNodes();
for (i=0;i<c;i++)
{
removeLastListNode();
}
}
printf("\n Malloc Calls = %d \n",malloc_calls);
printf("\n Free Calls = %d \n",free_calls);
}
void showAllListNodes()
{
struct ListNode *temp_ls = malloc(sizeof(struct ListNode));
malloc_calls++;
temp_ls = first_ls_;
while(temp_ls != NULL)
{
//printf("\n %d =%d= %d
Value=%d\n",temp_ls->previous,temp_ls,temp_ls->next,temp_ls->value);
temp_ls = temp_ls->next;
}
free(temp_ls);
free_calls++;
}
void addListNode(int value)
{
struct ListNode *temp_ls = malloc(sizeof(struct ListNode));
malloc_calls++;
temp_ls->previous = NULL;
temp_ls->value = value;
temp_ls->next = NULL;
temp_ls->previous = last_ls_;
last_ls_->next = temp_ls;
last_ls_ = temp_ls;
}
void removeLastListNode(void)
{
last_ls_ = last_ls_->previous;
free(last_ls_->next);
free_calls++;
last_ls_->next = NULL;
}