I'm currently learning how to code C++ and I need help...

I'm currently learning how to code C++ and I need help. I need to go through the list and remove all of the even integers. Then I need to output the list after inputting all of the integers and removing all of the even integers. I also need to test it with these integers : 7, 10, 5, 7, 9, 4, 2, 6, 10, 12, 3, 12, 5, 5, 2, 7, 2, 12, -1.

Can anyone help? I zuck ya dick.

Here's my code so far:

#include
using namespace std;

struct Node
{
int data;
Node* next;
};
void sortedInsert(Node** head_ref, int num)
{
Node* new_node = new Node;
new_node->data = num;
new_node->next = NULL;
/* Special case for the head end */
if (*head_ref == NULL || (*head_ref)->data >= new_node->data)
{
new_node->next = *head_ref;
*head_ref = new_node;
}
else
{
Node* current = *head_ref;
while (current->next!=NULL &&
current->next->data < new_node->data)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}
/* Function to print linked list */
void printList( Node *head)
{
Node *temp = head;
while(temp != NULL)
{
cout

Attached: 4chan-1320245729462.jpg (487x500, 34K)

Other urls found in this thread:

cpp.sh/2itqg
twitter.com/NSFWRedditVideo

Linked lists are inefficient. Use std::vector.

This is probably homework for a data structures class. Also op learn to use code tags that shit is unreadable

It's not homework, It's me trying to learn a computing language and not get left behind when machines take over the planet.

Code Tags Included.

#include
using namespace std;
/* Program to insert in a sorted list */
/* Link list node */
struct Node
{
int data;
Node* next;
};
void sortedInsert(Node** head_ref, int num)
{
Node* new_node = new Node;
new_node->data = num;
new_node->next = NULL;
/* Special case for the head end */
if (*head_ref == NULL || (*head_ref)->data >= new_node->data)
{
new_node->next = *head_ref;
*head_ref = new_node;
}
else
{
/* Locate the node before the point of insertion */
Node* current = *head_ref;
while (current->next!=NULL &&
current->next->data < new_node->data)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}
/* Function to print linked list */
void printList( Node *head)
{
Node *temp = head;
while(temp != NULL)
{
cout

Attached: 1503802905805.jpg (592x448, 18K)

No, write your own dynamic container.
How is he going to learn c++ without stepping on some rakes himself?

Then do it using arrays. Linked lists have no use in the real world.

This, literally.
Also use nullptr instead of NULL.

Why aren’t you just validating whether the number is even or odd before adding it to the list? Why wait until all the numbers were added?
Anyway I can think of two options to do what you want one is transverse the list and copy the odd numbers to a new list and return that one. Another is transverse the list and remove the even nodes. You will need to code a delete node function

Just get an array and put all odd numbers at the end and decrease the size counter lol.

You want to try that one more time?

Attached: puzzled cat.png (360x222, 30K)

If it's not homework and you want to learn C++ then stop programming in C with right now and pick up some tutorial or book from this decade...

This is the first step to improve your program. Don't code your own data structure. Also no new and delete.

Stop trying to make him a code monkey, he needs to learn what happens under the hood instead of using magical libraries.

use code tags op, i don't want to read your code otherwise

cpp.sh/5cocq

Guys I hear you and all, but one step at a time. I've taken all your advice into consideration and will definitely get to that a bit later, but
as says i'm trying to learn from the bare bones, every detail of C++, not just maximum efficiency stuff.

I'm using what I know to do it this way, so please, using the code I've already written can anyone help me achieve my goal of removing the even integers?

Attached: 1506760781490.jpg (852x480, 119K)

Throw C++ in the garbage and write C

Attached: RpRcWE.png (574x554, 363K)

Data structures are taught after you pass OOP class, leave them for now.

>learning OOP before data structures
what's wrong with you

I did it in python

let sorter=function(array){
let neww=[];
for(i in array){
if(array[i]%2!=0){
neww.push(parseInt(array[i]));
}
}
return neww;
}

let notsepples=function(arr){
let srted=sorter(arr);
while(true){
var a=prompt("this is actually ruby");
reg=/\D/;
if(reg.test(a)){
break;
}
else{
srted.push(parseInt(a));
}
}
let srtedagain=sorter(srted);
return srtedagain;
}

is there a guide to code tags not butchering my spacing or something?

here ya go OP
cpp.sh/2itqg

Huh? What's the purpose of learning raw boring theory without being able to apply it?

>OOP is necessary to use data structures

Attached: brainlet.png (645x729, 56K)

If you're learning C++, why waste time with python or some shit?

the fuck does python have to do with anything?

Holy shit are you daft?

> using namespace std;

try again

>C++

Just be lazy user, you're not supposed to think in C++.

#include
#include

std::vector List = { ... };
std::vector::iterator it;

for( it = List.begin() ; it !=List.end() ; ++it)
{
if( *it%2 ==0 ) it = List.erase(it);
}

Attached: nene1.png (900x506, 596K)

You shouldn't program without knowing what's underneath you. Rolling your own data structures for performance should only be done when profiling calls for it but as a learning exercise you've gotta know this stuff.

filterOdd xs = filter (mod x 2 /=0) xs

missing the point of C++ this much.
#include

template
void remove_if_even(Container &c)
{
c.erase(std::remove_if(c.begin(), c.end(), [](auto &e) { return !(e % 2); }), c.end());
}

Not OP, but why?

Not OP, but why?

filterOdd = filter odd

because the std namespace brings too much crap into scope. If there is a lot of std:: crap used, try using something like this:

template
void print_sequence(const Container &c)
{
using std::cout;
using std::stringstream;

stringstream ss;
for (auto &e : c) ss

It's typesafe.

Having using declarations for each symbol makes your code much more readable.

the only correct answer