Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰👨🏻💻👩🏻💻₰❥
عملية التقاطع intersection لعناصر قائمتين احادية single linked lists :-
#include <iostream>
using namespace std;
class Node
{
public:
int data;
Node *next;
};
int getCount(Node *head);
int _getIntesectionNode(int d, Node *head1, Node *head2);
int getIntesectionNode(Node *head1, Node *head2)
{
int c1 = getCount(head1);
int c2 = getCount(head2);
int d;
if (c1 > c2)
{
d = c1 - c2;
return _getIntesectionNode(d, head1, head2);
}
else
{
d = c2 - c1;
return _getIntesectionNode(d, head2, head1);
}
}
int _getIntesectionNode(int d, Node *head1, Node *head2)
{
Node *current1 = head1;
Node *current2 = head2;
for (int i = 0; i < d; i++)
{
if (current1 == NULL)
{
return -1;
}
current1 = current1->next;
}
while (current1 != NULL && current2 != NULL)
{
if (current1 == current2)
return current1->data;
current1 = current1->next;
current2 = current2->next;
}
return -1;
}
int getCount(Node *head)
{
Node *current = head;
int count = 0;
while (current != NULL)
{
count++;
current = current->next;
}
return count;
}
int main()
{
Node *newNode;
Node *head1 = new Node();
head1->data = 9;
Node *head2 = new Node();
head2->data = 6;
newNode = new Node();
newNode->data = 4;
head2->next = newNode;
newNode = new Node();
newNode->data = 3;
head2->next->next = newNode;
newNode = new Node();
newNode->data = 9;
head1->next = newNode;
head2->next->next->next = newNode;
newNode = new Node();
newNode->data = 3;
head1->next->next = newNode;
head1->next->next->next = NULL;
cout << "The node of intersection is " << getIntesectionNode(head1, head2);
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
المخـ₰💻₰❥ـرجات
The node of intersection is 9
[Program finished]
عملية التقاطع intersection لعناصر قائمتين احادية single linked lists :-
#include <iostream>
using namespace std;
class Node
{
public:
int data;
Node *next;
};
int getCount(Node *head);
int _getIntesectionNode(int d, Node *head1, Node *head2);
int getIntesectionNode(Node *head1, Node *head2)
{
int c1 = getCount(head1);
int c2 = getCount(head2);
int d;
if (c1 > c2)
{
d = c1 - c2;
return _getIntesectionNode(d, head1, head2);
}
else
{
d = c2 - c1;
return _getIntesectionNode(d, head2, head1);
}
}
int _getIntesectionNode(int d, Node *head1, Node *head2)
{
Node *current1 = head1;
Node *current2 = head2;
for (int i = 0; i < d; i++)
{
if (current1 == NULL)
{
return -1;
}
current1 = current1->next;
}
while (current1 != NULL && current2 != NULL)
{
if (current1 == current2)
return current1->data;
current1 = current1->next;
current2 = current2->next;
}
return -1;
}
int getCount(Node *head)
{
Node *current = head;
int count = 0;
while (current != NULL)
{
count++;
current = current->next;
}
return count;
}
int main()
{
Node *newNode;
Node *head1 = new Node();
head1->data = 9;
Node *head2 = new Node();
head2->data = 6;
newNode = new Node();
newNode->data = 4;
head2->next = newNode;
newNode = new Node();
newNode->data = 3;
head2->next->next = newNode;
newNode = new Node();
newNode->data = 9;
head1->next = newNode;
head2->next->next->next = newNode;
newNode = new Node();
newNode->data = 3;
head1->next->next = newNode;
head1->next->next->next = NULL;
cout << "The node of intersection is " << getIntesectionNode(head1, head2);
}
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja↷
•┈┈┈•❈••✦✾✦••❈•┈┈┈•
المخـ₰💻₰❥ـرجات
The node of intersection is 9
[Program finished]
غدا محاضرة فقط مع د عبد الكريم التبان من 10
المحاضرة حق بكرة موجودة في مكتبة التوحيد
المحاضرة حق بكرة موجودة في مكتبة التوحيد
جدول امتحانات الفصل الاول
295.8 KB
جدول امتحانات الفصل الاول
جدول امتحانات المحملين الفصل الاول
284.1 KB
جدول امتحانات المحملين الفصل الاول
Information Technology "IT" - level 4
شريحة 1.html
المحاضرة التاسعة MIS. مترجمة