| Thread Closed |
linked lists |
Share Thread |
| Sep26-05, 01:44 PM | #1 |
|
|
linked lists
I was wondering if anyone can help me with linked lists???
I have to create a linked list with 10 random numbers rangeing from 1-5 and insert them into a node in the appriote postion of a linearly linked list and display the number of times each number of occurences of each item. and i have to create a function that would delete the replicate items in the linked list and only leave one of the same numbers. and then display the linked list sorted and unique. I am having trouble starting this out because my teacher sucks and the book is horrible. I have tried help from computer people but it is still not sticking. I am sure if someone can help me get started i can probably get the rest done but i have no idea to get this started because i have only used c++.net and the teacher wants it done in c++6.0 so that is some of the trouble i am having so if someone can help i would be grateful. |
| Sep26-05, 04:45 PM | #2 |
|
|
#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'; } can someone please check me on this and see if this is a good start... |
| Thread Closed |
Similar discussions for: linked lists
|
||||
| Thread | Forum | Replies | ||
| Intro to linked lists | Programming & Comp Sci | 2 | ||
| Singly Linked Lists | Programming & Comp Sci | 1 | ||
| help with linked lists | Introductory Physics Homework | 1 | ||