Hi I just recently implemented a circular linked list in Java but I am having some troubles doing so in the (C) programming language - No entries will print to the console. Could someone help me with the insertion and output portion to my circular linked list?
Here is the Insertion function as well as the Output function.
/**
* FUNCTION : addWeapon
* DESCRIPTION : This function will add a new weapon to the weapon wheel.
* PARAMETERS : pWeaponHead
* RETURNS : true, false
*/
const bool addWeapon(struct Weapon* pWeaponHead, struct Weapon* pWeaponTail)
{
struct Weapon* pNewWeapon = NULL;
pNewWeapon = (struct Weapon*)malloc(sizeof(struct Weapon));
// Check the system for sufficient memory.
if (pNewWeapon == NULL) { return false; }
else
{
// We have memory for a new weapon entry.
getchar();
printf(KPROMPTFORWEAPON);
fgets(pNewWeapon->arsWeapon, K100BYTES, stdin);
newLineRemover(pNewWeapon->arsWeapon);
pNewWeapon->pNext = pNewWeapon;
// Is the weapon wheel empty ?
if (pWeaponHead == NULL)
{
pWeaponHead = pNewWeapon;
pWeaponTail = pNewWeapon;
return true;
}
pWeaponTail->pNext = pWeaponHead;
pNewWeapon->pNext = pNewWeapon;
pWeaponHead = pNewWeapon;
}
return true;
}
/**
* FUNCTION : showWeaponWheel
* DESCRIPTION : This function will display the weapon selection
* which is represented by the "Weapon Wheel" this allows
* us to choose which weapon we would like that exists in the list.
* PARAMETERS : pWeaponHead
* RETURNS : true, false
*/
const bool showWeaponWheel(struct Weapon* pWeaponHead)
{
// Check to see if the list is empty.
if (pWeaponHead == NULL) { return false; }
struct Weapon* pHead = pWeaponHead;
printf("** -- Weapon Wheel -- \n");
do
{
printf("\t%s\n", pHead->arsWeapon);
pHead = pHead->pNext;
} while (pHead != pWeaponHead);
return true;
}