موقع طلبة جامعة البحرين

يمكنك تصفح الموقع كزائر ولكن ندعوك لتسجيل عضوية خاصة بك لتحصل على كافة الصلاحيات مثل تنزيل ملفات المكتبة وقراءة تعليقات هيئة التدريس وغيرها. يمكنك الحصول على عضوية مجانية بالضغط على زر تسجيل. إذا قمت بالتسجيل مسبقا فيمكنك الضغط على زر دخول.

تسجيل دخول
  • قسم المكتبة الجامعية مغلق مؤقتا بعد الاستهداف التي تعرضت له بعض خدمات أمازون في البحرين، جاري استرجاع الملفات ونقلها إلى سيرفرات جديدة وسيتم بعدها اعادة افتتاح المكتبة

ITCS215 للفصل الدراسي الأول 2015 - 2016

في أحد فاهم سالفة الـ Composition ؟ :99:

مثلا طالبين منش هذا السؤال
write a class called person , having the following data members : name , cpr , and date of birth >>

name of type : string
cpr of type : long
ال date of birth ""هو الي فيه المشكله لان يحتوي 3 عناصر ال day / month / year "" انزين ويش الحل ؟ اول شي نكتب كلاس جديد بنسميه date مثلا وبنخلي فيه هالثلاث عناصر اله هي " day / month / year " وبعدين بنستخدم لكلاس date حق نعرف ال date of birth

HTML:
class Date
{
int day ; 
int month;
inth year;

public:
>>>>>>>>
>>>>>>>>>>
>>>>>>>
};

HTML:
class person
{
string name ;
long cpr;
Date date_of_birth;
public:
<<<<<<<<
<<<<<<
<<<<<<
};
 
مثلا طالبين منش هذا السؤال
write a class called person , having the following data members : name , cpr , and date of birth >>

name of type : string
cpr of type : long
ال date of birth ""هو الي فيه المشكله لان يحتوي 3 عناصر ال day / month / year "" انزين ويش الحل ؟ اول شي نكتب كلاس جديد بنسميه date مثلا وبنخلي فيه هالثلاث عناصر اله هي " day / month / year " وبعدين بنستخدم لكلاس date حق نعرف ال date of birth

HTML:
class Date
{
int day ; 
int month;
inth year;

public:
>>>>>>>>
>>>>>>>>>>
>>>>>>>
};

HTML:
class person
{
string name ;
long cpr;
Date date_of_birth;
public:
<<<<<<<<
<<<<<<
<<<<<<
};

شششكرا :RpS_love:
 
شعب ... وينكم
ليش مافي تفاعل !!!
 
بسم الله والحمد لله والصلاة والسلام على رسول الله وعلى اّله وصحبه ومن والاه



خلاص خلاص أنا أفعل الموضوع بعون الله
وأي خطاء الرجاء التصحيح



شرايكم نتناقش في موضوع Array-Based Lists

هاذي أريي جاهزة بالفنكشنات

من الفنكشنات اللي فيها

isEmpty() and isFull()

طبعاً واضحين من أسمهم

طريقة أستخدامهم

PHP:
template<class elemType>
bool arrayListType<elemType>::isEmpty()
{
return (length == 0);
}

والثانية

PHP:
template<class elemType>
bool arrayListType<elemType>::isFull()
{
return (length == maxSize);
}

وجزاكم الله خير
 
For the class LinkedListType, it is required to add a member function that takes an integer index position as a parameter. The function finds the data item inside the node at the index position and makes it available as the reference parameter item. The index of the first node is 0 and increases by 1 for each subsequent node. If the list is empty or the index is invalid then return false, else return true.
The function prototype:
;(bool retrieveAt(int position, Type& item
 
For the class LinkedListType, it is required to add a member function that takes an integer index position as a parameter. The function finds the data item inside the node at the index position and makes it available as the reference parameter item. The index of the first node is 0 and increases by 1 for each subsequent node. If the list is empty or the index is invalid then return false, else return true.
The function prototype:
;(bool retrieveAt(int position, Type& item

كود:
template<class type>
bool LinkedListType<type>::retrieveAt(int position, type& item)
{
	if (first==NULL)
	{
		cerr<<"List is empty"<<endl;
		return false;
	}
	if (position<0 || position>=count)
	{
		cerr<<"Invalid position"<<endl;
		return false;
	}
	nodeType<type> *current=first;
	for (int i=0;i<position;i++)
		current=current->link;
	Item=current->info;
	return true;
}
 
سكشن راكيش
قال بيعطينا كويز يوم الاربعاء في شنو الكوز عااد ؟؟ :nosweat:
 
سكشن 1
طلبة الدكتور احمد فهد

الدكتور شرح اليوم .. لو بس مراجعة ؟
 
سلام في احد يقدر يساعدني في السؤال
Create a new project in which you add the two header files: "arrayList.h" and "arrayListImplement.h" (will be provided). * The function remove of the class arrayListType*removes first occurrence of a specific element. Add the function removeAll*to the class arrayListType*that would remove all the occurrences of specific element from the list. The function removeAll*should use the remove function. Also, add the function ReplaceAll to the class arrayListType*that would receive two arguments and replace all the occurrences of the first argument with the second one. * Write a simple main to test the previous functions.
 
سلام في احد يقدر يساعدني في السؤال
Create a new project in which you add the two header files: "arrayList.h" and "arrayListImplement.h" (will be provided). * The function remove of the class arrayListType*removes first occurrence of a specific element. Add the function removeAll*to the class arrayListType*that would remove all the occurrences of specific element from the list. The function removeAll*should use the remove function. Also, add the function ReplaceAll to the class arrayListType*that would receive two arguments and replace all the occurrences of the first argument with the second one. * Write a simple main to test the previous functions.

كود:
template<class Type>
void arrayListType<Type>::removeAll(const Type& item)
{
	if(Empty())
		cerr<<"List is Empty"<<endl;
	else
	{
		int loc;
		while((loc=seqsearch(item))!=-1)
			removeAt(loc);
	}
}


template<class Type>
void arrayListType<Type>::ReplaceAll(const Type& item1,const Type& item2)
{
	if(Empty())
		cerr<<"List is Empty"<<endl;
	else
	{
		int loc;
		while((loc=seqsearch(item1))!=-1)
			replaceAt(loc,item2);
	}
}
 
شلون آسوي أدد للهيدر فايلز ؟؟؟؟؟؟
 
أحد منكم عنده حل Tutorial 1 و 2
بليييييز ردوو ضروري ؟؟؟؟؟؟ :RpS_crying::RpS_crying:
 
Extend the class linkedListType by adding the following operations:

1- Write a function noDuplicates that insert an item but before inserting the item it checks whether the item is already in the list. If the item to be inserted is already in the list, the function outputs an appropriate error message.
2- Write a function that returns the info of the kth element of the linked list. If no such element exists, output an appropriate message.


Write a program to test your functions.



Sample Input/Output

Enter the size of the List: 6

Enter a number to be inserted: 5
Enter a number to be inserted: 7
Enter a number to be inserted: 5

Item you are trying to insert is already in the list.

Enter a number to be inserted: 9
Enter a number to be inserted: 1
Enter a number to be inserted: 7

Item you are trying to insert is already in the list.

Enter a number to be inserted: 10
Enter a number to be inserted: 2

The Content of the list is:
5 7 9 1 10 2

Enter an index to return its value: 3
The value of index 3 is : 1


Press any key to continue……


plz help me
 
Extend the class linkedListType by adding the following operations:

1- Write a function noDuplicates that insert an item but before inserting the item it checks whether the item is already in the list. If the item to be inserted is already in the list, the function outputs an appropriate error message.
2- Write a function that returns the info of the kth element of the linked list. If no such element exists, output an appropriate message.


Write a program to test your functions.



Sample Input/Output

Enter the size of the List: 6

Enter a number to be inserted: 5
Enter a number to be inserted: 7
Enter a number to be inserted: 5

Item you are trying to insert is already in the list.

Enter a number to be inserted: 9
Enter a number to be inserted: 1
Enter a number to be inserted: 7

Item you are trying to insert is already in the list.

Enter a number to be inserted: 10
Enter a number to be inserted: 2

The Content of the list is:
5 7 9 1 10 2

Enter an index to return its value: 3
The value of index 3 is : 1


Press any key to continue……


plz help me

أتوقع ممنوع حل الأسايمنتز كامل ، فحطي جوابش هني و إن شاء الله بنحاول نساعدش فيه
 
#include<iostream>
using namespace std;

template<class Type>
struct nodeType
{
Type info;
nodeType<Type> *link;
};

template<class Type>
class linkedListType
{
public:
const linkedListType<Type>& operator=(const linkedListType<Type>&);
void initializeList();
bool isEmpty();
int length();
void destroyList();
Type front();
Type back();
bool search(const Type& searchItem);
void insertFirst(const Type& newItem);
void insertLast(const Type& newItem);
void deleteNode(const Type& deleteItem);
linkedListType();
linkedListType(const linkedListType<Type>& otherList);
~linkedListType();
void noDuplicates(const type& newitem);
const linkedListType<Type> & retrieveat(int loc)

//protected:
int count;
nodeType<Type> *first;
nodeType<Type> *last;

private:
void copyList(const linkedListType<Type>& otherList);
};

template<class Type>
class orderedLinkedListType: public linkedListType<Type>
{
public:
bool searcho(const Type& searchItem);
void insertNode(const Type& newItem);
void deleteNode(const Type& newItem);
};

template<class Type>
ostream& operator<<(ostream&, const linkedListType<Type>&);
}

#include"linklist.h"
#include<cassert>

template<class Type>
ostream& operator<<(ostream& osObject, const linkedListType<Type>& list)
{
nodeType<Type> *current; // pointer to traverse the list
current = list.first;
while(current != NULL)
{
osObject<<current->info<<" ";
current = current->link;
}
return osObject;
}

template<class Type>
const linkedListType<Type>& linkedListType<Type>::operator=(const linkedListType<Type>& otherList)
{
if(this != &otherList) //avoid self-copy
copyList(otherList);
return *this;
}

template<class Type>
void linkedListType<Type>::initializeList()
{
destroyList();
}


template<class Type>
bool linkedListType<Type>::isEmpty()
{
return(first == NULL);
}

template<class Type>
int linkedListType<Type>::length()
{
return count;
}

template<class Type>
void linkedListType<Type>::destroyList()
{
nodeType<Type> *temp;
while(first != NULL)
{
temp = first;
first = first->link;
delete temp;
}
last = NULL;
count = 0;
}

template<class Type>
Type linkedListType<Type>::front()
{
assert(last != NULL);
return first->info;
}

template<class Type>
Type linkedListType<Type>::back()
{
assert(last != NULL);
return last->info;
}

template<class Type>
bool linkedListType<Type>::search(const Type& searchItem)
{
nodeType<Type> *current;
bool found;
current = first;
found = false;
while(current != NULL && !found)
if(current->info == searchItem)
found = true;
else
current = current->link;
return found;
}

template<class Type>
void linkedListType<Type>::insertFirst(const Type& newItem)
{
nodeType<Type> *newNode;
newNode = new nodeType<Type>;
assert(newNode != NULL);
newNode->info = newItem;
newNode->link = first;
first = newNode;
count++;
if(last == NULL)
last = newNode;
}

template<class Type>
void linkedListType<Type>::insertLast(const Type& newItem)
{
nodeType<Type> *newNode;
newNode = new nodeType<Type>;
assert(newNode != NULL);
newNode->info = newItem;
newNode->link = NULL;
if(first == NULL)
{
first = newNode;
last = newNode;
}
else
{
last->link = newNode;
last = newNode;
}
count++;
}

template<class Type>
void linkedListType<Type>::deleteNode(const Type& deleteItem)
{
nodeType<Type> *current; // pointer to traverse the list
nodeType<Type> *trailCurrent; //pointer just before current
bool found;
if(first == NULL)
cout<<"Cannot delete from an empty list."<<endl;
else
{
if(first->info == deleteItem)
{
current = first;
first = first->link;
count--;
if(first == NULL) // list has only one node
last = NULL;
delete current;
}
else // search the list for the node with the given info
{
found = false;
trailCurrent = first;
current = first->link;
while(current != NULL && !found)
{
if(current->info != deleteItem)
{
trailCurrent = current;
current = current->link;
}
else
found = true;
}
if(found)
{
trailCurrent->link = current->link;
count--;
if(last == current) //node to be deleted is the last node
last = trailCurrent;
delete current;
}
else
cout<<"Item to be deleted is not in the list."<<endl;
}
}
}

template<class Type>
linkedListType<Type>::linkedListType()
{
first = NULL;
last = NULL;
count = 0;
}

template<class Type>
linkedListType<Type>::linkedListType(const linkedListType<Type>& otherList)
{
first = NULL;
copyList(otherList);
}

template<class Type>
linkedListType<Type>::~linkedListType()
{
destroyList();
}

template<class Type>
void linkedListType<Type>::copyList(const linkedListType<Type>& otherList)
{
nodeType<Type> *newNode; //pointer to create a node
nodeType<Type> *current; //pointer to traverse the list
if(first != NULL)
destroyList();
if(otherList.first == NULL) //otherList is empty
{
first = NULL;
last = NULL;
count = 0;
}
else
{
current = otherList.first; //current points to the lis to be copied
count = otherList.count;
first = new nodeType<Type>; //create the node
assert(first != NULL);
first->info = current->info; //copy the info
first->link = NULL; //set the link field of the node to NULL
last = first; //make last point to the first node
current = current->link; //make current point to the next node
while(current != NULL) //copy the remaining list
{
newNode = new nodeType<Type>; //create a node
assert(newNode != NULL);
newNode->info = current->info; //copy the info
newNode->link = NULL; //set the link of newNode to NULL
last->link = newNode; //attach newNode after last
last = newNode; //make last point to the actual last node
current = current->link; //make current point to the next node
}
}
}

template<class Type>
bool orderedLinkedListType<Type>::searcho(const Type& searchItem)
{
bool found;
nodeType<Type> *current;
found = false;
current = first;
while(current != NULL && !found)
if(current->info >=searchItem)
found = true;
else
current = current->link;
if(found)
found = (current->info == searchItem);
return found;
}

template<class Type>
void orderedLinkedListType<Type>::insertNode(const Type& newItem)
{
nodeType<Type> *current; //pointer to traverse the list
nodeType<Type> *trailCurrent; //pointer just before current
nodeType<Type> *newNode; //pointer to create a node
bool found;
newNode = new nodeType<Type>; //create the node
newNode->info = newItem; //store newitem in the node
newNode->link = NULL; //set the link field of the node to NULL

if(first == NULL) //case 1
{
first = newNode;
count++;
}
else
{
current = first;
found = false;
while(current != NULL && !found)
if(current->info >= newItem)
found = true;
else
{
trailCurrent = current;
current = current->link;
}
if(current == first) //case 2
{
newNode->link = first;
first = newNode;
count++;
}
else //case 3
{
trailCurrent->link = newNode;
newNode->link = current;
count++;
}
}
}

template<class Type>
void orderedLinkedListType<Type>::deleteNode(const Type& deleteItem)
{
nodeType<Type> *current; // pointer to traverse the list
nodeType<Type> *trailCurrent; //pointer just before current
bool found;
if(first == NULL) //case 1
cout<<"Cannot delete from an empty list."<<endl;
else
{
current = first;
found = false;
while(current != NULL && !found)
if(current->info >= deleteItem)
found = true;
else
{
trailCurrent = current;
current = current->link;
}
if(current == NULL) //case 4
cout<<"Item to be deleted is not in the list."<<endl;
else
if(current->info == deleteItem) //item to be deleted is in the list
{
if(first == current) //case 2
{
first = first->link;
delete current;
}
else //case 3
{
trailCurrent->link = current->link;
delete current;
}
count--;
}
else
cout<<"Item to be deleted is not in the list."<<endl;
}
}

tamplate<class type>
void orderedLinkedListType<Type>::noDuplicates(const type& newitem)
{
nodetype<type> *current;
bool found= false;
current=first;
while(current !=NULL &&!found)
{ if (current->info !=newitem)
current =current->link;
else
found= true;
cout<<" Item you are trying to insert is already in the list."<<endl;
}
if (found)
list.insertLast(newitem)
}


#include "linklist.h"
#include "lim.h"


int main()
{
int size;
linkedListType<int>list;

cout <<"Enter the size of the List:"<<endl;
cin>>size>>endl;

int item;
int newitem;
for (int i=0;i<size;i++)
{
cout<<"Enter a number to be inserted: "<<endl;
cin>>item;
item== newitem;
list.noDuplicates(newitem);
}
 
السلام عليكم .. شباب في أحد يقدر يساعدني في الاسايمنت ؟ حليته بس في ايرور واحد ..

السؤال :

Part A (10 points)

  1. Declare doubly linkedListType objects named list1 to handle string items.
  2. Insert the following items in list1 :20,30,7,8,99,0
  3. Print the elements of list1 in forword and reverse order respactivlly .
  4. Delete the following items 0,100,50
  5. Print the elements of list1 in forword order


Part B (5 points)
Write a member function called insertMiddle to be included in class doublyLinkedList to insert a specificItem in the middle of the list as follows:

  • List is empty: output message: “This is empty list”
  • List has one node :insert the new item at the end of the list.
  • Two or more than two node: insert in after the middle node.
  • Print the new list in forward order .

Hint: Sorted Doubly Linked List with Insertion and Deletion opration


جوابي :
كود:
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

class Dllist
{
   private:
       typedef struct Node
       {
          int info;
          Node* next;
          Node* prev;
       };
       Node* head;
       Node* last;
   public:
       Dllist()
       {
         head = NULL;
         last = NULL;
       }
       bool empty() const { return head==NULL; }
       friend ostream& operator<<(ostream& ,const Dllist& );
       void Insert(const int& );
       void Remove(const int& );
       void insertMiddle(const int&);
       void dispNodesForward(void);
       void dispNodesReverse(void) ;
       void splitlist(  void);
};

void Dllist::Insert(const int& s)
{
    // Insertion into an Empty List.
    if(empty())
    {
       Node* temp = new Node;
       head = temp;
       last = temp;
       temp->prev = NULL;
       temp->next = NULL;
       temp->info = s;
    }
    else
    {
       Node* curr;
       curr = head;
       while( s>curr->info && curr->next != last->next) curr = curr->next;

       if(curr == head)
       {
         Node* temp = new Node;
         temp->info = s;
         temp->prev = curr;
         temp->next = NULL;
         head->next = temp;
         last = temp;
      //  cout<<" Inserted "<<s<<" After "<<curr->info<<endl;
       }
       else
       {
       if(curr == last && s>last->info)
       {
         last->next = new Node;
         (last->next)->prev = last;
         last = last->next;
         last->next = NULL;
         last->info = s;
      //  cout<<" Added "<<s<<" at the end "<<endl;
       }
       else
       {
         Node* temp = new Node;
         temp->info = s;
         temp->next = curr;
         (curr->prev)->next = temp;
         temp->prev = curr->prev;
         curr->prev = temp;
      //  cout<<" Inserted "<<s<<" Before "<<curr->info<<endl;
       }
      }
    }
}

ostream& operator<<(ostream& ostr, const Dllist& dl )
{
    if(dl.empty()) ostr<<" The list is empty. "<<endl;
    else
    {
        Dllist::Node* curr;
        for(curr = dl.head; curr != dl.last->next; curr=curr->next)
          ostr<<curr->info<<" ";
        ostr<<endl;
        ostr<<endl;
        return ostr;
    }
}

void Dllist::Remove(const int& s)
{
    bool found = false;
    if(empty())
    {
      cout<<" This is an empty list! "<<endl;
      return;
    }
    else
    {
      Node* curr;
      for(curr = head; curr != last->next; curr = curr->next)
      {
          if(curr->info == s)
          {
             found = true;
             break;
          }
      }
      if(found == false)
      {
       cout<<" The list does not contain specified Node"<<endl;
       return;
      }
      else
      {
         // Curr points to the node to be removed.
         if (curr == head && found)
         {
           if(curr->next != NULL)
           {
            head = curr->next;
            delete curr;
            return;
           }
           else
           {
            delete curr;
            head = NULL;
            last = NULL;
            return;
           }
         }
        if (curr == last && found)
        {
         last = curr->prev;
         delete curr;
         return;
        }
       (curr->prev)->next = curr->next;
       (curr->next)->prev = curr->prev;
        delete curr;
     }
  }
}
void Dllist:: splitlist()
{
 Dllist d2,d3;
    //bool found = false;
    if(empty())
    {
      cout<<" This is an empty list! "<<endl;
      return;
    }
    else
    {
      Node* curr;
      Node*c2=head; Node* c3=head;
      for(curr = head; curr != last->next; curr = curr->next)
      {
          if(curr->info %2 == 0)
          
             d2.Insert(curr->info);
           else 
            
          d3.Insert(curr->info);
      }
      
}
 
  d2.dispNodesForward();cout<<endl;
 
 
    d3.dispNodesForward();    }

void Dllist::dispNodesForward() 
  { 
      Node *temp = head; 
      cout << "\n\nNodes in forward order:" << endl; 
      while(temp != NULL) 
      { 
         cout << temp->info << "   " ; 
         temp = temp->next; 
      } 
  } 
  void Dllist::dispNodesReverse() 
  { 
      Node *temp = last; 
      cout << "\n\nNodes in reverse order :" << endl; 
      while(temp != NULL) 
      { 
         cout << temp->info << "   " ; 
         temp = temp->prev; 
      } 
  }
  
  
void Dllist::insertMiddle(const int& s)
{
if(empty())
    {
       cout<<"empty";
    }
    else    
    {
        Node* curr;        
        Node* temp = new Node;               
       temp->next = curr;
       temp->prev = last;
       last->next = temp;
       last = temp; 
       }
       else
       {
           temp->prev = curr;
           temp->next = curr->next;
           curr->next->prev = temp;
           curr->next = temp;
       }                                                   
}
int main()
{
    Dllist list1;
    list1.Insert(20);
    list1.insertMiddle(30);
    list1.insertMiddle(7);
    list1.insertMiddle(8);
    list1.insertMiddle(99);
    list1.Insert(0);
    list1.dispNodesForward();
    list1.dispNodesReverse();
    cout<<endl;
    list1.Remove(0);
    list1.Remove(100);
    list1.Remove(50);
    cout<<endl;
    cout << "\n\nNodes in forward order:" << endl;
    cout<<list1<<endl;



           system("pause");
                  return 0;
                
   
}
 
Write a function (not a member function) called reorderAt that takes two objects L1 and L2 of type arrayListType as parameters. The function reorders the elements of L1 based on the values in L2. For each element in L1 there is a corresponding number in L2 such that the number in L2 represents the new position/index for the element to be placed in L1. In other words, the number in L2 specifies the index where the element should be re-placed in L1. L2 is of the same size as L1.
Assume that the positions specified by elements of L2 are valid positions.
Example
Array of L1: { a b c d }
Array of L2: { 3 0 2 1 }
After function call array of L1 will be { b d c a }
0 1 2 3
The function prototype:
void reorderAt( arrayListType<Type>& L1, arrayListType<Type>& L2 );
Hint: Create a new list L3 as a copy of list L1. Replace elements of L3 by elements of L1 at position specified by list L2. Assign L3 to L1.​
 
عودة
أعلى أسفل