Thread: Help with static linked list

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    3

    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
    Registered User
    Join Date
    Jan 2014
    Posts
    3
    The program is like this so far:
    Code:
    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;
    }

  3. #3
    Registered User
    Join Date
    Jan 2014
    Posts
    3
    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:
    Code:
    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

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    I see you failed to use code tags over here as well -> Help With Static Linked List - Dev Shed

    Perhaps you should begin by focussing on making a decent post on just one forum, rather than hastily scattering copy/paste over the fora.
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Codes? I thought this was a programming forum, not a cryptography forum.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 09-22-2013, 10:34 PM
  2. Changing static array database system to linked list
    By DLH112 in forum C Programming
    Replies: 13
    Last Post: 12-09-2009, 12:50 PM
  3. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  4. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  5. Replies: 5
    Last Post: 04-09-2004, 10:13 AM