السلام عليكم ورحمة الله وبركاته ..
يااخوان عندي اسئلة في البرمجة .. فيه بعضها عرفتها لكن بعضها حاولت وماقدرت ..
هذا الكود
#include <iostream>
#include <list>
#include <conio>
#include <iterator>
using namespace std;
/////////////////////
//DEFINING THE NODE//
/////////////////////
struct newNode
{
int data;
newNode *next;
};
/////////////////////////////////////
///dfining terms in the dictionary///
/////////////////////////////////////
struct terms {
char term[20]; //array of 20 elements
struct newNode *link; //linked list of type newNode
}term1,term2;
struct newNode *create_list(); //Function that creates a linked list
struct newNode *merge(struct newNode *list1 ,struct newNode *list2);//merging function
////////
//MAIN//
////////
///////////////////////////////////////////////////////////////////////////////
int main() //
{ //
struct newNode *posting_list1; //
struct newNode *posting_list2; //
struct newNode *result; //
struct newNode *leader; //
//
cout<<"\nENTER THE FIRST TERM: "; //
cin>>term1.term; //
//
posting_list1= create_list(); //
term1.link=posting_list1; //
//
cout<<"\nENTER THE SECOND TERM: "; //
cin>>term2.term; //
posting_list2= create_list(); //
term2.link=posting_list2; //
//
result=merge(posting_list1,posting_list2); //
//
/////////////////////////////// //
///////PRINT THE RESULT//////// //
/////////////////////////////// //
//
leader = result; //
if (leader != 0) //PRINT if the result is not EMPTY //
cout<<"intersection the posting lists of " //
<<term1.term<<" and "<<term2.term<<" is : \n"; //
while (leader != 0) //
{ //
cout << leader->data << endl; //
leader = leader->next; //
} //
//
getch(); //
return 0; //
} //
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//FUNCTION CREATES LINKED LIST AND RETURNS THE FIRST NODE//
//////////////////////////////////////////////////////////
struct newNode *create_list()
{
newNode *origon;//first node
newNode *leader;//moves through nodes
int data = 0;//SET data TO 0 INCASE USER DOES NOT ENTER ANY DATA VALUE;
//////////////////////////////
//THIS creats the list //
//////////////////////////////
cout << "Enter a number or (enter -999 to quit): " << endl;
cin >> data;
origon = new newNode;//create the first node in the linked list
origon->next=0; //set that link to 0 (or null)
origon->data = data; //set origion to make the first node = the user input(data)
leader = origon ;//now the leader points to first node
while (data != -999)//as long as the users input isn't -999, keep storing data
{
cin >> data; //gets user data, if -999 quit
leader ->next = new newNode;//creates a new node at the end of the list
leader = leader ->next; //moves to it (new node)
leader->data = data; // insert the data
leader ->next = 0; //sets it to 0 (null)
}
return(origon);
}
////////////////////////////////////////////////////////////////////////
///////////////////////////MERGE FUNCTION//////////////////////////////
///////////////////////////////////////////////////////////////////////
struct newNode *merge(struct newNode *list1 ,struct newNode *list2)
{
struct newNode *result;
struct newNode *origon;
origon = new newNode;//create the first node in the linked list
origon->next=0; //set that link to 0 (or null)
origon->data=0; //set an initial value
result = origon ;//now the leader points to first node
while (list1 != 0 && list2 != 0 )
{
if (list1->data == list2->data)
{
result->next = new newNode;
result = result->next;
result->data = list1->data;
result->next = 0;
list1=list1->next; ////////////////// MOVE BOTH LISTS///////////////
list2=list2->next; /////////////////////////////////////////////////
}
else
if (list1->data < list2->data)
list1 = list1->next; ////////////////// MOVE LIST1///////////////
else
list2 = list2->next; ////////////////// MOVE LIST2///////////////
}
result = origon->next; //because origon->data = 0 (initial value)
if (origon->next == 0) //if the result is empty list
{
cout << "there is no documents that contanis both words" <<endl;
return 0;
}
else
return(result);
}السؤال .. فيه تغيير بسيط في الخوارزمية الموجوده في الكود فقط ..
Modfy the perivous code to perform the UNION of tow posting lists
And add the term FREQUENCY to the term's structure (complete the dictionary)
انتظر مساعدتكم ..يااخوان .. ارجوكم .. ساعدوني :)

