#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0

    Help With Static Linked List


    Can Someone please help me figure this out?! I have the codes for the functions, now I just need to make this list but i'm having a hard time. The question is as follow:

    "Given the functions that we have discussed and defined in the class and the code that we have created, create the code for the DeleteNode function and the Search function. Create an application that will incorporate all the functions that we have discussed and the new ones that you need to create. The application should allow the linked list to be built initially from a text file. The application should then allow for the user select an operation to perform. The acceptable operations are
    - to search for an item
    - to delete an item
    - to enter a new item
    - to exit the application

    After the initial build and loading of data from the textfile, the application should print a listing of each item in the list and the node that it is located in.
    after a delete or insert, the application should display an output of the list again showing each item in the list and the node that it resides in.

    The dataitem for this problem will be the inventory structure that we created in class and the data is in the inventory file that you already have downloaded."
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0
    The functions I have are:

    struct node
    {
    int dataitem;
    int link;
    };

    void initList( struct node [], int *, int);
    void findNode( struct node [], int*);
    int ReadData( struct node [], int*);
    void Add2List(struct node[], int , int);


    int _tmain(int argc, _TCHAR* argv[])
    {
    struct node linkList[21];
    int start, current, newnode;

    initList(linkList, &start, 21);

    printf("Enter and integer value : ");
    ReadData(linkList,&newnode);

    Add2List(linkList, start, newnode);

    printf("Enter and integer value : ");
    ReadData(linkList,&newnode);

    Add2List(linkList, start, newnode);


    current = start;
    while (current != -1)
    {
    printf("the data is %d and the link value is %d\n\n",
    linkList[current].dataitem,
    linkList[current].link);
    current= linkList[current].link;
    }


    return 0;
    }

    void initList( struct node linkList[],int *ptr, int listSize)
    {
    *ptr = 0;
    linkList[*ptr].link = -1;
    linkList[*ptr].dataitem = 0;


    for (int current = 1; current < listSize; current++)
    linkList[current].link = 0;
    }

    void findNode(struct node LinkList[], int *next)
    {
    int current = 1;

    while (LinkList[current].link != 0)
    {

    current++;
    }
    *next = current;
    }

    int ReadData(struct node linkList[], int *NewNode)
    {
    findNode(linkList, NewNode);

    scanf("%d", &linkList[*NewNode].dataitem);

    return 0;
    }

    void Add2List(struct node linkList[], int start, int newnode)
    {
    int current = start;

    while (linkList[current].link != -1)
    current = linkList[current].link;

    linkList[current].link = newnode;

    linkList[newnode].link = -1;

    linkList[start].dataitem += 1;
    }

    void DeleteNode(struct node linkList[], int start, int oldData)
    {
    int current, oldNode;

    current = SearchList( linkList, start, oldData);
    oldNode = linkList[current].link;
    linkList[current].link = linkList[oldNode].link;
    linkList[oldNode].link = 0;
    linkList[start].dataitem -= 1;
    }

    int SearchList(struct node linkList[], int start, int oldData)
    {
    int current = start;

    while (linkList[linkList[current].link].dataitem != oldData)
    current = linkList[current].link;

    return current;
    }
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0
    For this assignment, the ReadData Function will read all elements from the file (inventory.txt). The SearchList is assumed to be a "part.no" from the file.
    It should look something like this:
    struct node{
    struct inventory dataItem;
    int link;
    }

    And then I would have to reference a struct within a structure...
    The items in the inventory.txt are as follow:

    #1 Flat Blade Screwdriver
    12489
    36
    .65
    1.75
    #2 Flat Blade Screwdriver
    12488
    24
    .70
    1.85
    #1 Phillips Screwdriver
    12456
    27
    0.67
    1.80
    #2 Phillips Screwdriver
    12455
    17
    0.81
    2.00
    Claw Hammer
    03448
    14
    3.27
    4.89
    Tack Hammer
    03442
    9
    3.55
    5.27
    Cross Cut Saw
    07224
    6
    6.97
    8.25
    Rip Saw
    07228
    5
    6.48
    7.99
    6" Adjustable Wrench
    06526
    11
    3.21
    4.50

IMN logo majestic logo threadwatch logo seochat tools logo