Submit the following: Revised algorithm for the addrecord and deleterecord with
ID: 3853785 • Letter: S
Question
Submit the following:
Revised algorithm for the addrecord and deleterecord with C code
Below each line in the algorithm, write the corresponding C code. If needed, insert curly braces (keep the indents unchanged!).
Example:
If you have the following pseudocode,
define an int called i
if( i is not 0 )
copy 0 to i
You need to insert lines of C code like this.
define an int called i
int i;
if( i is not 0 )
if( i != 0 )
{
copy 0 to i
i = 0;
}
Traces that verify the algorithm for the following test cases:
Adding two duplicate records to an empty list
Beginning with a list that consists entirely of two duplicate records, delete all duplicates so you end with an empty list.
-------------------------------------------------------------------------------------
This is my psudocode:
-----------------------------------
addRecord
------------------------------------
addRecord()
define a pointer to record called temp
allocate space on the heap and store its address into temp
copy from uaccountno to accontno in record whose address is in temp
copy from uname to name in record whose address is in temp
copy from uaddress to address in record whose address is in temp
copy null to next in record whose address is in temp
if(start is null)
copy from temp to start
else
define a pointer to record called s
copy from start to s
while(next from record whose address is in s is not null)
copy from next from record whose address is in s to s
copy from temp to next from record whose address is in s
-----------------------------------
deleteRecord
-----------------------------------
deleteRecord(define an int called accNo)
if(start is not null)
define a record called temp
copy from start to temp
while(next from record whose address is in temp is not NULL)
if(accNo is accountno from record whose address is in start and next from record whose address is in start is NULL)
release the space whose address is in temp
copy NULL to start
else if(accNo is accountno from record whose address is in start)
copy from next from record whose address is in start to start
release the space whose address is in temp
else if(accNo is accountno from record whose address is in next)
define a record called temp1
copy from next from record whose address is in temp to temp1
copy from next from record whose address is in next to next
release the space whose address is in temp1
else
copy from next from record whose address is in temp to temp
Explanation / Answer
this is my psudo code:
To add a record
int temp->null;
int *p=&temp;
int add=&temp;
strcpy(accountno,uaccountno);
strcpy(name,uname);
strcpy(address,uaddress);
strcpy(null,temp->next)
if(start!=NULL)
strcpy(start,temp);
else
int *ptr=s;
strcpy(s,start);
while(s->next!=NULL)
strcpy(s,s->next);
strcpy(s->next,temp);
To delete a record
deleteRecord(int accNo)
if(start!=NULL)
int temp2;
strcpy(temp,start);
while(temp->next!=NULL)
if(accno=accountno&&temp->next!=NULL)
free(temp);
strcpy(start,NULL);
else if(accno=accountno&temp=&start)
strcpy(start->next,start);
elseif(accno=accountno&temp->next=next)
int temp1;
strcpy(temp1,temp->next);
strcpy(temp->next,next);
free(temp1);
else
strcpy(temp->next,next);