Here is the code with my attempt at the insert function. Before the insert function the linked list did work properly. Now it has 28 errors-I am in over my head.
insert
Code:
#include "stdafx.h"
#include "stdlib.h"
#include "string.h"
#define maxnum 10
struct value
{
int num[maxnum];
struct value*nextaddr;
}
int _tmain(int argc, _TCHAR* argv[])
{
int a,b,c,d,e,f;
firstRec=Null;
void readInsert();
printf("please enter five numbers:");
scanf("%d,%d,%d,%d,%d", &a,&b,&c,&d,&e,&f);
struct value t1={a};
struct value t2={b};
struct value t3={c};
struct value t4={d};
struct value t5={e};
struct value *first;
void display (struct value*);
first=&t1;
t1.nextaddr=&t2;
t2.nextaddr=&t3;
t3.nextaddr=&t4;
t4.nextaddr=&t5;
t5.nextaddr=NULL;
display (first);
readInsert();
return 0;
}
void display(struct value*contents)
{
while (contents!=NULL)
{
printf("%d", *contents->num);
contents=contents->nextaddr;
}
}
void readInsert()
{
int num[maxnum];
int newval;
void insert(int*);
printf("enter another number:");
scanf("%d",&newval);
insert(newval);
}
void insert(int*newval)
{
srtuct value *linear Locate(int*);
srtuct value *newaddr, *here;
newaddr=(struct value*) malloc (sizeof(struct value));
if (newaddr==(struct value*) NULL)
{
printf("\n Could not allocate the requested space\n");
exit(1);
}
if (&t1==NULL)
{
newaddr->nextaddr=NULL;
&t1=newaddr;
}
else if (strcmp(newval, &t1->newval)<0)
{
newaddr->nextaddr=&t1;
=newaddr;
}
else
{
here=linear Locate(newval);
newaddr->nextaddr=here->nextaddr;
here->nextaddr=newaddr;
}
strcpy(nexaddr->newval, newval);
}
my attempt at the function is my adaptation of how the book used it, for I don't know how to use it myself.