Results 1 to 25 of 25

Thread: Help w/project + linked list Plz Read

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40

    Arrow Help w/project + linked list Plz Read

    Ok I have this project to do and its like impossible to do!?
    Im supposed to create a double linked list implemented as a class and have ( insert, delete, search, traverse ) The structure used for it should have fields for ( name, ssn, age & occupation ) The search, delete func perform their functions give a persons name. The program fills up the linked list using a data file. Then the program presents the user with options ( display a record, add a record, delete a record and exit ) The display, add, and delete operations should request a name and display an error if the name doesnt exist in the list. Then on exit the program writes the linked list back to the data file.

    A same file I guess looks like this
    Smith, Bob
    123-34-3333
    43
    Engineer

    Im soo lost on this project.

    The code for the class though is this:
    PHP Code:
    Class LL
    {
    private:
    record *head;
    record *tail;
    public:
    LL();
    int insert (record *);
    record *search(char[]);
    int delete_item(char[]);
    void traverse[];
    }
    LL:: ( LL )
    {
    head NULL;
    tail NULL;

    Id be willing to pay someone ! I need u geniouses

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    That's about the 5th linked list post in one week...

    UTFSF!
    Use The *****ing Search Function!

    Two or three days ago I posted a list of the threads concerning linked lists, and one of these links contains both a C and a C++ implementation of a linked list, also both written by me.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    I know I posted a full mailing list app in C using LL's , as well.
    It must be final project season in beginning C/C++ classes...


  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yep, also I've seen a VERY similar exercise. Also was about cars and SSNs...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by jim mcnamara
    I know I posted a full mailing list app in C using LL's , as well.
    It must be final project season in beginning C/C++ classes...

    Too ****ing right.

    I am sick and tired of people posting their homework questions. I have no problem with them having difficulties, we're happy to help.

    But for God's sake don't give a half-arsed class layout and expect us to do your homework!

    && drunk...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    Originally posted by parksie
    Too ****ing right.

    I am sick and tired of people posting their homework questions. I have no problem with them having difficulties, we're happy to help.

    But for God's sake don't give a half-arsed class layout and expect us to do your homework!

    && drunk...
    why not? dont u guys luv what u do?

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Heh, sorry about the rant back there

    I do love what I do, but the idea is for us to help people, not do it for them, else nobody will ever learn.

    We've just had a bit of a glut of people asking obvious homework questions, that's all.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yes, you are mainly that "unlucky kid who came in at the time when everybody just said that they would kill the next one to come in". That's all.

    But nevertheless the search function should give you a big jump start. If you have specific problems come back.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    ok well, ill try the search func, but can u guys help me still ? ill be back later

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Of course
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    ok guys, I dunno im just really confused on the code for linked list. I think I just need an insert node I think, and Im not sure where to begin.

    Heres some of the code so far, but its scattered a bit. Im not sure what the parameters are for traverse, delete etc. I need some kinda start. Im gonna keep reading up on it and workin on it right now.

    PHP Code:
    #include "stdafx.h"
    #include <fstream>
    #include <iostream>


    struct record
    {
        
    char name[50];
        
    char ssn[12];
        
    char age[4];
        
    char occupation[50];
        
    record *next;
        
    record *prev;
    };




    Class 
    LL
    {
    private:
    record *head;
    record *tail;
    public:
    LL();
    int insert (record *);
    record *search(char[]);
    int delete_item(char[]);
    void traverse[];
    }
    LL:: ( LL )
    {
    head NULL;
    tail NULL;
    }



    int LL:insert(     )



    void LL:traverse(     )




    void LL:DeleteNode(      )
    {
        --(
    ll->size);
        
    at->prev->next at->next;
        
    at->next->prev at->prev;
        
    free(at);
    }




    int main(int argccharargv[])
    {

    menu();


        return 
    0;
    }





    int menu ()
    {
        
    int item;
        
    // display menu and return output

        
    cout << "===============================" << endl;
        
    cout << "      Please Select An Option            " << endl << endl;
        
    cout << " 1. Display a record" << endl;
        
    cout << " 2. Add a record" << endl;
        
    cout << " 3. delete a record" << endl;
        
    cout << " 4. Exit" << endl;
        
        
        
    cin >> item;
        
    cin.ignore ();

        
    // return item
        
    return item;


    I just wanna get it done before the weekend cuz its due next tuesday, and I have plans for the weekend. But Im gona do my best with everyones help

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I corrected some syntax errors, but not yet supplied code for the missing functions.

    PHP Code:
    #include "stdafx.h"
    #include <fstream>
    #include <iostream>
    [b]using namespace std;[/b]

    struct record
    {
        
    char name[50];
        
    char ssn[12];
        
    char age[4];
        
    char occupation[50];
        
    record *next;
        
    record *prev;
    };




    Class 
    LL
    {
    private:
    record *head;
    record *tail;
    public:
    LL();
    int insert (record *);
    record *search(char[]);
    int delete_item(char[]);
    [
    b]void traverse();[/b]
    [
    b]};[/b]

    [
    b]LL::LL()[/b]
    {
    head NULL;
    tail NULL;
    }

    // You need to pass data to insert.
    int LL:insert()
    {
    }

    // Actually this function can't do anything
    void LL:traverse()
    {
    }

    // Need to pass an at pointer
    [b]void LL::DeleteNode()[/b]
    {
        --(
    ll->size);
        
    at->prev->next at->next;
        
    at->next->prev at->prev;
        
    free(at);
    }

    int main(int argccharargv[])
    {
        
    menu();
        return 
    0;
    }

    int menu ()
    {
        
    int item;
        
    // display menu and return output

        
    cout << "===============================" << endl;
        
    cout << "      Please Select An Option          " << endl << endl;
        
    cout << " 1. Display a record" << endl;
        
    cout << " 2. Add a record" << endl;
        
    cout << " 3. delete a record" << endl;
        
    cout << " 4. Exit" << endl;
        
        
        
    cin >> item;
        
    cin.ignore ();

        
    // return item
        
    return item;

    Is the list sorted? Or should it be in random order? The implementation of insert depends on that.
    Look at the insert implementations in my code, they are not that hard to understand (and I can explain them if you want).
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    ya its gotta be a sorted list, and why cant traverse do anything? Im supposed to have it.

    ya plz explain.

  14. #14
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    A traverse function doesn't really make sense, you usually do the traversing directly (in C) or via iterators (in C++). traverse can't do what it's name implies without using function pointers, which you should avoid.

    Traverse could also take a node pointer and return the next node, but why do
    Node *p;
    p = traverse(p);
    when you can do
    p = p->next;
    ?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  15. #15

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    well, my teacher is retarded, i guess we're supposed to use function pointers. I dunno.

  16. #16

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    I know this isnt really the " right " thing to ask. But would u or anyone except money for the code? I hate to ask it, and I know I should be learning this stuff, but its just that I dont really have an interest in programming and dont understand it that much. I guess I just wanna get done with this last programming class so I can move on to networking, which is my major pretty much.

    So sorry if I upset u cornedbee or anyone else, but I guess Im just desperate? I would pay though

  17. #17
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It is more trouble arranging such a payment that it's worth...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  18. #18

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    Originally posted by CornedBee
    It is more trouble arranging such a payment that it's worth...
    why? paypal is so easy
    Last edited by havoq93; Oct 24th, 2002 at 10:31 AM.

  19. #19

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    Ok ive gotten this far. Can u help out on some of these other functions like the insert one, or fix mistakes i might have?

    PHP Code:
    #include "stdafx.h"
    #include <fstream>
    #include <iostream>

    using namespace std;


    struct record
    {
        
    char name[50];
        
    char ssn[12];
        
    char age[4];
        
    char occupation[50];
        
    struct record *next;
        
    struct record *prior;
    };

    struct record *start;  /* pointer to first entry in list */
    struct record *last;  /* pointer to last entry */
    struct record *find(char *);


    Class 
    LL {
    private:
    record *head;
    record *tail;
    public:
    LL();
    int insert (record *);
    record *search(char[]);
    int delete_item(char[]);
    void traverse[];
    };
    LL:: ( LL )
    {
    head NULL;
    tail NULL;
    };


    int LL:insert(     )



    void LL:traverse(     )





    void LLdelete_item(struct record **startstruct record **last)
    {
      
    struct record *info;
      
    char s[80];

      
    inputs("Enter name: "s30);
      
    info find(s);
      if(
    info) {
        if(*
    start==info) {
          *
    start=info->next;
          if(*
    start) (*start)->prior NULL;
          else *
    last NULL;
        }
        else {
          
    info->prior->next info->next;
          if(
    info!=*last)
              
    info->next->prior info->prior;
          else
            *
    last info->prior;
        }
        
    free(info);  /* return memory to system */
      
    }
    }


    /* Look for a name in the list. */
    void search(void)
    {
      
    char name[50];
      
    struct record *info;

      
    printf("Enter name to find: ");
      
    gets(name);
      
    info find(name);
      if(!
    infoprintf("Not Found\n");
      else 
    display(info);
    }


    /* Load the record file. */
    void load()
    {
      
    struct record *info;
      
    FILE *fp;

      
    fp fopen("assign6""rb");
      if(!
    fp) {
        
    printf("Cannot open file.\n");
        exit(
    1);
      }

      
    /* free any previously allocated memory */
      
    while(start) {
        
    info start->next;
        
    free(info);
        
    start info;
      }

      
    /* reset top and bottom pointers */
      
    start last NULL;

      
    printf("\nLoading File\n");
      while(!
    feof(fp)) {
        
    info = (struct record *) malloc(sizeof(struct record));
        if(!
    info) {
          
    printf("Out of Memory");
          return;
        }
        if(
    != fread(infosizeof(struct record), 1fp)) break;
        
    dls_store(info, &start, &last);
      }
      
    fclose(fp);
    }


    /* Save the file to disk. */
    void save(void)
    {
      
    struct record *info;

      
    FILE *fp;

      
    fp fopen("assign6""wb");
      if(!
    fp) {
        
    printf("Cannot open file.\n");
        exit(
    1);
      }
      
    printf("\nSaving File\n");

      
    info start;
      while(
    info) {
        
    fwrite(infosizeof(struct record), 1fp);
        
    info info->next;  /* get next address */
      
    }
      
    fclose(fp);
    }




    int main(int argccharargv[])
    {

     
    start last NULL;  /* initialize start and end pointers */

      
    for(; {
        switch(
    menu()) {
          case 
    1display(); 
            break;
          case 
    2add_rec(); 
            break;
          case 
    3DeleteNode(); 
            break;
          case 
    4: exit(0); 
         
        }
      }
      return 
    0;
    }




    int menu ()
    {
        
    int item;
        
    // display menu and return output

        
    cout << "===============================" << endl;
        
    cout << "      Please Select An Option            " << endl << endl;
        
    cout << " 1. Display a record" << endl;
        
    cout << " 2. Add a record" << endl;
        
    cout << " 3. delete a record" << endl;
        
    cout << " 4. Exit" << endl;
        
        
        
    cin >> item;
        
    cin.ignore ();

        
    // return item
        
    return item;


    my class is also messup I think cuz i keep getting
    C:\Program Files\Microsoft Visual Studio\assign6\assign6.cpp(26) : error C2146: syntax error : missing ';' before identifier 'LL'
    C:\Program Files\Microsoft Visual Studio\assign6\assign6.cpp(26) : error C2501: 'Class' : missing storage-class or type specifiers
    Last edited by havoq93; Oct 24th, 2002 at 11:48 AM.

  20. #20
    Addicted Member
    Join Date
    Jan 2002
    Location
    Michigan
    Posts
    143
    anyone?

  21. #21
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Class

    as far as I know C++ uses class and is case-sensitive...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  22. #22

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    ya i figured that out the other day, I shoulda mentioned it, so u didnt waste a post on me like that. lol

    what about the rest of the code? right trail?

    PHP Code:
    #include "stdafx.h"
    #include <fstream>
    #include <iostream>

    using namespace std;


    struct record
    {
        
    char name[50];
        
    char ssn[12];
        
    char age[4];
        
    char occupation[50];
        
    struct record *next;
        
    struct record *prior;
    };

    struct record *start;  /* pointer to first entry in list */
    struct record *last;  /* pointer to last entry */
    struct record *find(char *);


    void list(void);

    void search(void);
    void display(struct record *);
    void dls_store(struct record *istruct record **startstruct record **last);

    int menu();

    class 
    LL 
    {
    private:
    record *head;
    record *tail;
    public:
    LL();
    int insert(record data);
    record *search(char[]);
    int delete_item(char[]);
    void traverse(void);
    };
    LL::LL ( )
    {
    head NULL;
    tail NULL;
    }


    /* Load the record file. */
    void load()
    {
      
    struct record *info;
      
    FILE *fp;

      
    fp fopen("assign6""rb");
      if(!
    fp) {
        
    printf("Cannot open file.\n");
        exit(
    1);
      }

      
    /* free any previously allocated memory */
      
    while(start) {
        
    info start->next;
        
    free(info);
        
    start info;
      }

      
    /* reset top and bottom pointers */
      
    start last NULL;

      
    printf("\nLoading File\n");
      while(!
    feof(fp)) {
        
    info = (struct record *) malloc(sizeof(struct record));
        if(!
    info) {
          
    printf("Out of Memory");
          return;
        }
        if(
    != fread(infosizeof(struct record), 1fp)) break;
        
    dls_store(info, &start, &last);
      }
      
    fclose(fp);
    }



    /* Create a doubly linked list in sorted order. */
    int LL::insert record data 
    {
      
    record *newnode = new record;  // make a new node
      
    *newnode data;  // copy the data
      
    newnode->next NULL;
      
    newnode->priorNULL// initialise the links
      
    if ( head == NULL ) {
        
    // list is empty, and now there is one
        
    head tail newnode;
      } else {
        
    // add node to the head of the list
        
    newnode->next head;
        
    head->prior newnode;
        
    head newnode;
      }
      return 
    0;
       }





    /* Display the entire list. */
    void list(void)
    {
      
    struct record *info;

      
    info start;
      while(
    info) {
        
    display(info);
        
    info info->next;  /* get next address */
      
    }
      
    printf("\n\n");
    }


    /* This function actually prints the fields in each record. */
    void display(struct record *info)
    {
        
    printf("%s\n"info->name);
        
    printf("%s\n"info->ssn);
        
    printf("%s\n"info->age);
        
    printf("%s\n"info->occupation);
        
    printf("\n\n");
    }


    int menu ()
    {
        
    int item;
        
    // display menu and return output

        
    cout << "===============================" << endl;
        
    cout << "      Please Select An Option            " << endl << endl;
        
    cout << " 1. Display a record" << endl;
        
    cout << " 2. Add a record" << endl;
        
    cout << " 3. delete a record" << endl;
        
    cout << " 4. Exit" << endl;
        
        
        
    cin >> item;
        
    cin.ignore ();

        
    // return item
        
    return item;
    }


    int main(int argccharargv[])
    {

        
    int temp =0;

    do {
        
        
        
    temp menu ();
        switch(
    temp)
        {

          case 
    1: list();
            break;
          case 
    4: exit(0); 
            break;

          default:
              
    cout << temp << " is invalid!" << endl;
              }
    } while (
    temp != 4);

    return 
    0;


    Last edited by havoq93; Oct 25th, 2002 at 01:29 PM.

  23. #23

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    OK seriously, where do I go from here?

    PHP Code:
    using namespace std;


    struct record
    {
        
    char name[50];
        
    char ssn[12];
        
    char age[4];
        
    char occupation[50];
        
    struct record *next;
        
    struct record *prior;
    };



    struct record *start;  /* pointer to first entry in list */
    struct record *last;  /* pointer to last entry */
    struct record *find(char *);


    void list(void);

    void search(void);
    void display(struct record *);
    void dls_store(struct record *istruct record **startstruct record **last);

    int menu();

    class 
    LL 
    {
    private:
    record *head;
    record *tail;
    public:
    LL();
    int insert(record data);
    int read_in(record *, char*);
    record *search(char[]);
    int delete_item(char[]);
    void traverse(void);
    };
    LL::LL ( )
    {
    head NULL;
    tail NULL;
    }





    int LL::insert record data 
    {
      
    record *newnode = new record;  // make a new node
      
    *newnode data;  // copy the data
      
    newnode->next NULL;
      
    newnode->priorNULL// initialise the links
      
    if ( head == NULL ) {
        
    // list is empty, and now there is one
        
    head tail newnode;
      } else {
        
    // add node to the head of the list
        
    newnode->next head;
        
    head->prior newnode;
        
    head newnode;
      }
      return 
    0;
       }





    /* Display the entire list. */
    void list(void)
    {
      
    struct record *info;

      
    info start;
      while(
    info) {
        
    display(info);
        
    info info->next;  /* get next address */
      
    }
      
    printf("\n\n");
    }


    /* This function actually prints the fields in each record. */
    void display(struct record *info)
    {
        
    printf("%s\n"info->name);
        
    printf("%s\n"info->ssn);
        
    printf("%s\n"info->age);
        
    printf("%s\n"info->occupation);
        
    printf("\n\n");
    }


    int menu ()
    {
        
    int item;
        
    // display menu and return output

        
    cout << "===============================" << endl;
        
    cout << "      Please Select An Option            " << endl << endl;
        
    cout << " 1. Display a record" << endl;
        
    cout << " 2. Add a record" << endl;
        
    cout << " 3. delete a record" << endl;
        
    cout << " 4. Exit" << endl;
        
        
        
    cin >> item;
        
    cin.ignore ();

        
    // return item
        
    return item;
    }


    int main(int argccharargv[])
    {
        
    int temp =0;

    do {    
        
        
    temp menu ();
        switch(
    temp)
        {

          case 
    1: list();
            break;
          case 
    4: exit(0); 
            break;

          default:
              
    cout << temp << " is invalid!" << endl;
              }
    } while (
    temp != 4);

    return 
    0

  24. #24
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Sorry, I just don't have the time to do this now.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  25. #25

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    40
    someones got time, who else?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width