Question
Can someone fix my pseudocode so it will perform as the example given below? This is my pseudocode: define a pointer to record called temp
Can someone fix my pseudocode so it will perform as the example given below?
This is my pseudocode:
define a pointer to record called temp allocate a heap space and store its address into temp
/* Allows user's account number to be stored in the record, else it would look if the address match a previous address by copying addresses in start and temp to avoid duplicates */
if( start is not equal to NULL ) if( uaccountno is not equal to accountno in the record whose address is in temp)
copy from uaccountno to accountno in the record whose address is in temp
copy from uname to name in the record whose address is in temp
copy from uaddress to address in the record whose address is in temp copy from NULL to next in the record whose address is in temp
else
copy from accountno in the record whose address is in start to accountno in the record whose address is in temp
copy from name in the record whose address is in start to name in the record whose address is in temp
copy from address in the record whose address is in start to address in the record whose address is in temp
copy from next in the record whose address is in start to next in the record whose address is in temp
/* head points to temp in the linked list whose accountno is either equal or smaller to uaccountno, and tail points to temp just before head. This way we get the linked list sorted */
define a pointer to record call head copy from start to head
define a pointer to record called tail copy from NULL to tail
while ( accountno in the record whose address is in head is greater to uaccountno )
copt from head to tail
copy from next in the record whose address is in head to head
copy from next in record whose address is in tail to next in the record whose address is in temp
copy from temp to next in the record whose address is in tail
This is how my pseudocode supposes to work.
-
Adding a record to an empty list
For example,
- uaccountno: 1000
- uname: Spongebob Squarepants
- uaddress: 123 Bikini Bottom
- Heap: No record
-
Adding a record to a list which has two records (every account number is different form others)
For example,
- uaccountno: 1000
- uname: Spongebob Squarepants
- uaddress: 123 Bikini Bottom
- Heap:
- Record1:
- accountno: 1200
- name: Plankton
- address: 321 Chum Bucket
- Record2:
- accountno: 900
- name: Mr.Krabs
- address: 231 Krusty Krab
- Record1:
-
Adding a record to a list that has two records (the second existing record has the same account number as that of the new record)
For example,
- uaccountno: 1000
- uname: Spongebob Squarepants
- uaddress: 123 Bikini Bottom
- Heap:
- Record1:
- accountno: 1200
- name: Plankton
- address: 321 Chum Bucket
- Record2:
- accountno: 1000
- name: Mr.Krabs
- address: 231 Krusty Krab
- Record1:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started