rendered paste body#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
double key;
char *val;
struct node *next;
};
double access(double x, struct node *p);
void insert(struct node **p, double k, char *b);
void print(struct node *p);
void removee(struct node **p, double k) {
struct node *ntr;
while (*p) {
if ((*p)->next->key == k) {
}
*p = (*p)->next;
}
}
struct node *make_node() {
struct node* n = (struct node *)malloc(sizeof(struct node));
n->next = NULL;
return n;
}
int main() {
struct node *ptr = NULL;
insert(&ptr, 2.5, "Tomek");
print(ptr);
getchar();
return 0;
}
void insert(struct node **p, double k, char *b)
{ struct node *ntr;
struct node *ptr = make_node();
if (*p == NULL) {
ptr->key = k;
ptr->val = (char *)malloc(strlen(b)+1);
strcpy(ptr->val, b);
*p = ptr;
}
else
{
if (k<(*p)->key)
{ ptr->key = k;
ptr->next = *p;
*p = ptr;
}
else
{ ntr = *p;
while (ntr->next)
{ if ((k>ntr->key) && (k<=ntr->next->key))
{ptr->key = k;
ptr->next = ntr->next;
ntr->next = ptr;
return;
}
ntr = ntr->next;
}
if (ntr->next==NULL)
{ ptr->key = k;
ptr->next = NULL;
ntr->next = ptr;
}
}
}
}
void print(struct node *p) {
if (p == NULL)
return;
printf("%f %s \n", p->key, p->val);
p = p->next;
}
double access(double x, struct node **p) {
struct node *ntr = (struct node *)malloc(sizeof(struct node));
while(*p) {
if ((*p)->key == x)
return x;
else {
ntr->key = 0;
ntr->val = (char *)malloc(8);
strcpy(ntr->val, "default");
ntr->next = *p;
*p = ntr;
}
*p = (*p)->next;
}
return 0;
}