heavyc Posted September 27, 2005 Posted September 27, 2005 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 ); } }
Dave Posted September 27, 2005 Posted September 27, 2005 Don't get what you're trying to do here. The program's just a simple linked-list program, and you need to actually write the unlink() function (I presume). Need more detail on what you're expected to do here. You also need to indent your code. I edited your post to put code tags around the appropriate bits so that they display better.
heavyc Posted September 27, 2005 Author Posted September 27, 2005 Don't get what you're trying to do here. The program's just a simple linked-list program' date=' and you need to actually write the unlink() function (I presume). Need more detail on what you're expected to do here. You also need to indent your code. I edited your post to put code tags around the appropriate bits so that they display better.[/quote'] the first program is a program that generates 10 random numbers and the second is a function that will find duplicate numbers in the random numbers and delete them but i dont know how to incorporate this into the main program(ie.. what varibles are going to be used for i and j because i never wrote how to unlink anything..
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now