Esempio n. 1
0
//===================================================================
// Function to undo a delete of a company.  Does not allow to undo
// delete of a company that is already in the BST
//===================================================================
void undoDelete(DATA_HEAD *data)
{
    COMPANY* companyNode;
    int isDuplicate;

    //If there is something in the stack
    if(!emptyStack(data->pStack))
    {
        companyNode = (COMPANY*)popStack(data->pStack);

        //Check to see if there is duplicate
        isDuplicate = searchHash(data, companyNode->companyName, companyNode);

        //If there is, print and error, else, insert into the hashed array
        if(isDuplicate == 1)
        {
            printf("ERROR: DUPLICATE DATA\n");
            printf("%s has already been entered into the system\n", companyNode->companyName);
            free(companyNode);
        }
        else
        {
            printf("%s reinserted into the system\n", companyNode->companyName);
            insertManager(data, companyNode);
            updateCollision(data);
            (data->count)++;
            printf("\nNumber Of Data Records: %d\n", data->count);
        }
    }
    else
        printf("Nothing to undo.\n"); //nothing in the stack

    printf("\n");
}
Esempio n. 2
0
//===================================================================
// Prompts for a new company to insert.  If already exists, return
// error. If does not exist, ask user for all information for company
// and inserts into the BST and hashed array
//===================================================================
void insertCompany(DATA_HEAD *data)
{
    COMPANY *newCompany;
    int len;
    char name[MAX_CHARS];

    printf("Enter name of company: ");
    fgets(name, MAX_CHARS, stdin);
    len = strlen(name);
    if(name[len-1] == '\n' || name[len-1]=='\r')
            name[len-1]='\0'; // change '\n' to '\0'

    newCompany = (COMPANY*)malloc(sizeof(COMPANY));
    if(newCompany == NULL)
    {
        printf("Not enough memory, exiting program...\n");
        exit(1);
    }
    newCompany->companyName = allocateString(name);
    //if search tree function returns succes
    if(!searchHash(data, name, newCompany)) //company name has not been found, therefore does not exist in tree.
    {
        printf("Enter revenue per billion: ");
        scanf("%d", &(newCompany->revenuePerBillion));
        printf("Enter profits per million: ");
        scanf("%d", &(newCompany->profitPerMillion));
        printf("Enter number of employees: ");
        scanf("%d", &(newCompany->numberOfEmployees));
        insertManager(data, newCompany);
        (data->count)++;
        printf("%s added!\n", newCompany->companyName);
        printf("\nNumber Of Data Records: %d\n\n", data->count);
    }
    else
        printf("ERROR: DUPLICATE DATA\n");

    printf("\n");
}
//***********************************************************************************************************
// Definition operationManager
//
//***********************************************************************************************************
void operationManager(listHead *aList, char tUserInput)
{
    if (tUserInput == 'i')
    {
        insertManager(aList);
    }
    else
    {
        if (tUserInput == 'd')
        {
            deleteManager(aList);
        }
        else
        {
            if (tUserInput == 'p')
            {
                searchHashManager(aList);
            }
            else
            {
                if (tUserInput == 'n')
                {
                    // Insert search bst manager
                }
                else
                {
                    if (tUserInput == 'k')
                    {
                        // Insert list data in street number sequence
                    }
                    else
                    {
                        if (tUserInput == 'h')
                        {
                            // Insert list data in hash table sequence
                        }
                        else
                        {
                            if (tUserInput == 't')
                            {
                                // Insert print indented tree
                            }
                            else
                            {
                                if (tUserInput == 's')
                                {
                                    // Display hash statistics
                                    aList->getHashPtr()->hashStatistics();
                                }
                                else
                                {
                                    // Otherwise, display menu
                                    displayMenu();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    
    return;
}// End operation manager