Single-link list

help.I need to create a list of paired positive elements of two input lists
where is the mistake?
#include <iostream>
#include <Windows.h>
using namespace std;
struct a
{
int e;
a* next;
};
void print(a* list)
{
while (list)
{
cout << list->e << " ";
list = list->next;
}
}
//a* insert_after(a* pos, int val)
//{
//
//}
int main()
{
system("cls");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int n,m,j;
a* begin = NULL;
a* last = NULL;
a* list = NULL;
a* begin1 = NULL;
a* last1 = NULL;
a* list1 = NULL;
a* list2 = NULL;
a* last2 = NULL;
a* begin2 = NULL;
cout << "n = ";
cin >> n;
cout << "m = ";
cin >> m;
while (n > 0)
{
last = new a;
last->e = rand() % 100 - 50;
if (begin == NULL)
{
last->next = NULL;
begin = last;
}
else
{
last->next = NULL;
list->next = last;
}
list = last;
n--;
}
while (m > 0)
{
last1 = new a;
last1->e = rand() % 100 - 50;
if (begin1 == NULL)
{
last1->next = NULL;
begin1 = last1;
}
else
{
last1->next = NULL;
list1->next = last1;
}
list1 = last1;
m--;
}
cout << "\nlist 1 = \n";
print(begin);
cout << "\nlist 2 = \n";
print(begin1);
j = -1;
/*while (list)
{
if (list->e > 0 and list->e % 2 == 0)
{
list->e = list2->e;
j++;
}
list = list->next;
}
while (list1)
{
if (list1->e > 0 and list1->e % 2 == 0)
{
list1->e = list2->e;
j++;
}
list1 = list1->next;
}*/
while (list)
{
if (list->e > 0 and list->e % 2 == 0)
{
list->e=list2->e;
list2 = list2->next;
}
list = list->next;
}
while (list1)
{
if (list1->e > 0 and list1->e % 2 == 0)
{
list1->e = list2->e;
list2 = list2->next;
}
list1 = list1->next;
}
cout << "\n list 3 = \n";
print(begin2);
while (begin)
{
list = begin;
begin = list->next;
delete list;
}
delete begin;
while (begin1)
{
list = begin1;
begin1 = list1->next;
delete list1;
}
delete begin1;
system("pause");
return 0;
}
use code tags ain't noone reading that the way it is.
what do you mean "tags"?
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.
> where is the mistake?
¿what are the symptoms? ¿compile error? ¿crash? ¿freeze? ¿bad output? ¿fever? ¿diarrhea?


> create a list of paired positive elements
don't know what you mean, provide an example
Topic archived. No new replies allowed.