User profile: marekmagic

User info
User name:marekmagic
Bio:SPOJKOVY ZOZNAM

TSTUDENT* root = NULL;
TSTUDENT* curr = NULL;
TSTUDENT* prev = NULL;

char buffer[100];
while (fgets(buffer,101,file))
{
curr = parse(buffer);
if (curr == NULL) return NULL;
curr->next = NULL;
if (root == NULL) root = curr;
else prev->next = curr;
prev = curr;
}
return root;
________________________________________________

BINARNE VYHLADAVANIE

int L = 0;
int R = pocet - 1;
int S;
int hladana_hodnota;
int *pole;

while (L<=P)
{
S=(L+P)/2;
if (pole[S]>hladana_hodnota) P=S-1;
else if (pole[S]<hladana_hodnota) L=S+1;
else return pole[S];
}
return NULL;

________________________________________________
TRIEDENIE

char **sort_strings(char **strings, int n)
{
if (strings==NULL) return NULL;
int vymena=1,i;
char *pom;

while(vymena==1)
{
for(i=0;i<(n-1);i++)
{
if(strcmp(strings[i],strings[i+1])>0)
{
pom=strings[i];
strings[i]=strings[i+1];
strings[i+1]=pom;
vymena=1;
}
else vymena=0;
}
}
print_strings(strings,n);
return strings;
}
________________________________________________
INSERT

NODE* insert(NODE *first, int n){
// create new node
NODE* new = (NODE*)malloc(sizeof(NODE));
new->data = n;
new->next = NULL;

// if first is NULL, this will be the first
if(first == NULL)
return new;

// otherwise, place it correctly
NODE* ptr = first;

// check inserting at the begining
if(ptr->data > new->data){
new->next = ptr;
return new;
}

// insert in the middle
while(ptr->next != NULL){
if(ptr->next->data > n && ptr->data < n){
new->next = ptr->next;
ptr->next = new;
break;
}
ptr = ptr->next;
}

// insert at the end of list
if(ptr->next == NULL){
ptr->next = new;
}

return first;
}
________________________________________________

TRAVERSE

void traverse(NODE *first){
NODE* ptr = first;
while(ptr != NULL){
printf("%d\n", ptr->data);
ptr = ptr->next;
}
}

________________________________________________

SEARCH

NODE* search(NODE* first, int n){
NODE* ptr = first;
while(ptr != NULL){
if(ptr->data == n){
printf("Found %d!\n", n);
return ptr;
}
ptr = ptr->next;
}

return NULL;
}

________________________________________________
History
Joined:
Number of posts:1
Latest posts:

How to free chain link consisting of this structure?
typedef struct tpatient { char* name; char* surname; TADDRESS* address; char* id; ...