1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Incorporate another function into this problem C++

  1. Sep 27, 2005 #1
    i have this problem and i am having trouble how to incorporate another function into this problem here is the problem..

    #include <iostream>

    using namespace std;

    struct node {
    int data;
    node *next;
    };

    struct node *push_front ( node *list, int data )
    {
    node *p = new node;

    p->data = data;
    p->next = list;
    list = p;

    return list;
    }

    int main()
    {
    node *list = 0;
    node *save;

    for ( int i = 0; i < 10; i++ )
    list = push_front ( list, rand() % 5 + 1 );

    while ( list != 0 ) {
    save = list->next;
    cout<< list->data <<' ';
    delete list;
    list = save;



    }

    cout<<'\n';
    }

    and here is what i am trying to put in.., i have it written but i dont know what varibles to put and where to put it into the program..

    for ( i = first; i != last; i = next ( i ) ) {
    for ( j = next ( i ); j != last; j = next ( j ) ) {
    if ( i == j )
    unlink ( j );
    }
    }
     
  2. jcsd
  3. Sep 28, 2005 #2

    andrevdh

    User Avatar
    Homework Helper

    Right up to the last part:
    makes sense (except for a few minor problems), but nobody on earth understands this last part. What are you trying to do with this part of the code? It seems you are travesing a new type of linked list (with the first and last nodes named) and at some node (j) you want to break the list into a new list or either cut the node (j) out of the original list.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Incorporate another function into this problem C++
  1. Pow function in C (Replies: 2)

  2. Another problem! (Replies: 1)

  3. Another problem (Replies: 1)

Loading...