Jump to content

need some help with program!!!

Featured Replies

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 );
}
}

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.

  • Author
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..

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.