Information Technology "IT" - level 4
503 subscribers
688 photos
40 videos
834 files
170 links
رابط قناة المراجع والملخصات والنماذج والمحاضرات
@Al_Adeeb_Group
Download Telegram
تنبيه ⭕️ :
الي مايكتب اسمه او يغيب عن الامتحان يحرم من الامتحان النهائي النظري .
Forwarded from ❥͢ ❈↡< C++ > برمجة (❥ツ)
إ₰👨🏻‍💻👩🏻‍💻₰❥

عملية الاتحاد union لعناصر قائمتين احادية single linked lists :-

#include <iostream>
using namespace std;
class list
{
public:
struct Node
{
int data;
Node *next;
};
Node *head = NULL;
Node *counter = NULL;

void insert(int value)
{
Node *newnode = new Node();
newnode->data = value;
newnode->next = NULL;

if (head == NULL)
{
head = counter = newnode;
return;
}
else
{
Node *temp = head;
while (temp->next != NULL)
{
temp = temp->next;
}

temp->next = newnode;
}
}


void display_elements()
{
Node *temp = head;
while (temp != NULL)
{
cout << temp->data << "\t";
temp = temp->next;
}
}
};


void find_union(list l1, list l2)
{
bool found = false;
list union_elements;
union_elements = l2;
while (l1.counter != NULL)
{
while (union_elements.counter != NULL)
{
if (l1.counter->data == union_elements.counter->data)
{
found = true;
break;
}
union_elements.counter = union_elements.counter->next;
}
if (found == 0)
union_elements.insert(l1.counter->data);
union_elements.counter = union_elements.head;
l1.counter = l1.counter->next;
found = 0;
}
union_elements.display_elements();
cout << endl;
cout << "----------------------------------------" << endl;
}
int main()
{
list ls, lis;
ls.insert(2);
ls.insert(5);
ls.insert(3);
ls.insert(9);
cout << "----------------------------------------" << endl;
cout << "this the first linkedlist" << endl;
cout << endl;
ls.display_elements();
cout << endl;
lis.insert(5);
lis.insert(3);
lis.insert(7);
cout << "----------------------------------------" << endl;
cout << "this the second linkedlist" << endl;
cout << endl;
lis.display_elements();
cout << endl;
cout << "----------------------------------------" << endl;
cout << "this the union of tow linkedlists" << endl;
cout << endl;
find_union(ls, lis);
}


•┈┈┈•❈••✦✾✦••❈•┈┈┈•
❥➺┊ @barrmaja
•┈┈┈•❈••✦✾✦••❈•┈┈┈•


المخـ₰💻₰❥ـرجات


----------------------------------------
this the first linkedlist
2 5 3 9
----------------------------------------
this the second linkedlist
5 3 7
----------------------------------------
this the union of tow linkedlists
5 3 7 2 9
--------------------------------------
[Program finished]
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]
غدا محاضرة فقط مع د عبد الكريم التبان من 10
المحاضرة حق بكرة موجودة في مكتبة التوحيد
حل سؤال الاستاذ علي الماوري ( نظام المنح الجامعية )