Your Perfect Assignment is Just a Click Away

We Write Custom Academic Papers

100% Original, Plagiarism Free, Customized to your instructions!

glass
pen
clip
papers
heaphones

De Anza College Code Oriented Pseudocode or a C++ Function Project

De Anza College Code Oriented Pseudocode or a C++ Function Project

Description

Write a code oriented pseudocode or a C++ function that swaps two consecutive nodes in a doublylinked list by updating their pointers (the data field inside the linked list node is not to be accessed). It returns true if possible, false otherwise. Assume the list has two sentinel nodes and n > 0. For instance, if n = 3 and list has the following data: SENTF 20 90 70 80 10 SENTRafter the call (70 and 80 are swapped)list is: SENTF 20 90 80 70 10 SENTR

struct Node

{

Node *back;

Data data;

Node *forw;

};

class DList

{

private:

Node *head;

int length;

Node *tail;

public:

bool swap(int n);

//node number n with node number n+1

};

This is my answer:

bool DList::swap(int n) {

   Node *temp = head;
int count = 0;
while (temp->forw != NULL) {
if (count == n) {
Node *temp1 = new Node;
Node *temp2 = new Node;
temp2 = temp->back->back;
Node *temp3 = new Node;
temp3=temp->forw;

temp1 = temp;
temp1->forw = temp->back;
temp1->back = temp->back->back;

temp = temp1->forw;
temp->back = temp1;
temp->forw = temp3;

temp2->forw = temp1;//80

return true;
}

else {
temp = temp->forw;
count++;
}
}

return false;
}

The next question is What happens if the list has only one number or n > length?

Order Solution Now

Our Service Charter

1. Professional & Expert Writers: School Class Pro only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by School Class Pro are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. School Class Pro is known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At School Class Pro, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.