Help With Linked Lists - Struggling to Get Started

  • Thread starter Thread starter heavyc
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on creating a linked list in C++ 6.0 that contains 10 random numbers ranging from 1 to 5. The user seeks assistance in implementing functionality to insert these numbers into the appropriate position in a linearly linked list, count occurrences of each number, and delete duplicate items to ensure uniqueness. The provided code snippet demonstrates the initial setup of a linked list and the insertion of random numbers, but lacks the required functionality for counting and deleting duplicates.

PREREQUISITES
  • Understanding of linked list data structures
  • Proficiency in C++ programming, specifically C++ 6.0
  • Knowledge of random number generation in programming
  • Familiarity with memory management and pointers in C++
NEXT STEPS
  • Implement a function to count occurrences of each number in the linked list
  • Develop a function to delete duplicate nodes from the linked list
  • Learn about sorting algorithms to sort the linked list
  • Explore C++ STL (Standard Template Library) for alternative data structures
USEFUL FOR

Students learning data structures, C++ developers needing to implement linked lists, and anyone looking to enhance their understanding of memory management in C++.

heavyc
Messages
16
Reaction score
0
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.
 
Physics news on Phys.org
some code i think

#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;
count<< list->data <<' ';
delete list;
list = save;
}

count<<'\n';
}

can someone please check me on this and see if this is a good start...
 

Similar threads

Replies
1
Views
2K
Replies
12
Views
2K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 64 ·
3
Replies
64
Views
6K
Replies
7
Views
1K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 2 ·
Replies
2
Views
1K
Replies
4
Views
2K
Replies
1
Views
1K
  • · Replies 17 ·
Replies
17
Views
2K