C++ using Linked Lists: There is consideration on an update to the new health ca
ID: 3822307 • Letter: C
Question
C++ using Linked Lists: There is consideration on an update to the new health care mandate in an attempt to offset the low participation. The powers to be are considering matching a well to do individual with a not so well to do individual. Every individual has been ranked with a priority where each individual has a unique ranking. Your assignment is to match the most well to do individual with the least well to do individual for the remaining individuals in the list.Your supposed to read in the data from 'OBCarall.dat' which the data in the file is shown below.
See example below. Input: 1 3 8 2 7 5 6 4 Output: 1 8; 2 7; 3 6; 4 5
The input file shows the following data inside:
35 65 52 3 142 147 139 51 79 5 59 54 70 45 113 124 22 42 89 34 130 37 55 110 120 57 48 32 80 99 40 27 143 123 24 17 28 58 72 74 133 62 146 141 86 6 69 119 41 18
C++ using Linked Lists: There is consideration on an update to the new health care mandate in an attempt to offset the low participation. The powers to be are considering matching a well to do individual with a not so well to do individual. Every individual has been ranked with a priority where each individual has a unique ranking. Your assignment is to match the most well to do individual with the least well to do individual for the remaining individuals in the list.
Your supposed to read in the data from 'OBCarall.dat' which the data in the file is shown below.
See example below. Input: 1 3 8 2 7 5 6 4 Output: 1 8; 2 7; 3 6; 4 5
The input file shows the following data inside:
35 65 52 3 142 147 139 51 79 5 59 54 70 45 113 124 22 42 89 34 130 37 55 110 120 57 48 32 80 99 40 27 143 123 24 17 28 58 72 74 133 62 146 141 86 6 69 119 41 18
C++ using Linked Lists: There is consideration on an update to the new health care mandate in an attempt to offset the low participation. The powers to be are considering matching a well to do individual with a not so well to do individual. Every individual has been ranked with a priority where each individual has a unique ranking. Your assignment is to match the most well to do individual with the least well to do individual for the remaining individuals in the list.
Your supposed to read in the data from 'OBCarall.dat' which the data in the file is shown below.
See example below. Input: 1 3 8 2 7 5 6 4 Output: 1 8; 2 7; 3 6; 4 5
The input file shows the following data inside:
35 65 52 3 142 147 139 51 79 5 59 54 70 45 113 124 22 42 89 34 130 37 55 110 120 57 48 32 80 99 40 27 143 123 24 17 28 58 72 74 133 62 146 141 86 6 69 119 41 18
C++ using Linked Lists: There is consideration on an update to the new health care mandate in an attempt to offset the low participation. The powers to be are considering matching a well to do individual with a not so well to do individual. Every individual has been ranked with a priority where each individual has a unique ranking. Your assignment is to match the most well to do individual with the least well to do individual for the remaining individuals in the list.
Your supposed to read in the data from 'OBCarall.dat' which the data in the file is shown below.
See example below. Input: 1 3 8 2 7 5 6 4 Output: 1 8; 2 7; 3 6; 4 5
The input file shows the following data inside:
35 65 52 3 142 147 139 51 79 5 59 54 70 45 113 124 22 42 89 34 130 37 55 110 120 57 48 32 80 99 40 27 143 123 24 17 28 58 72 74 133 62 146 141 86 6 69 119 41 18
C++ using Linked Lists: There is consideration on an update to the new health care mandate in an attempt to offset the low participation. The powers to be are considering matching a well to do individual with a not so well to do individual. Every individual has been ranked with a priority where each individual has a unique ranking. Your assignment is to match the most well to do individual with the least well to do individual for the remaining individuals in the list.
Your supposed to read in the data from 'OBCarall.dat' which the data in the file is shown below.
See example below. Input: 1 3 8 2 7 5 6 4 Output: 1 8; 2 7; 3 6; 4 5
The input file shows the following data inside:
35 65 52 3 142 147 139 51 79 5 59 54 70 45 113 124 22 42 89 34 130 37 55 110 120 57 48 32 80 99 40 27 143 123 24 17 28 58 72 74 133 62 146 141 86 6 69 119 41 18
C++ using Linked Lists: There is consideration on an update to the new health care mandate in an attempt to offset the low participation. The powers to be are considering matching a well to do individual with a not so well to do individual. Every individual has been ranked with a priority where each individual has a unique ranking. Your assignment is to match the most well to do individual with the least well to do individual for the remaining individuals in the list.
Your supposed to read in the data from 'OBCarall.dat' which the data in the file is shown below.
See example below. Input: 1 3 8 2 7 5 6 4 Output: 1 8; 2 7; 3 6; 4 5
The input file shows the following data inside:
35 65 52 3 142 147 139 51 79 5 59 54 70 45 113 124 22 42 89 34 130 37 55 110 120 57 48 32 80 99 40 27 143 123 24 17 28 58 72 74 133 62 146 141 86 6 69 119 41 18
Explanation / Answer
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cstring>
using namespace std;
class llist
{
private:
int rank;
llist *next;
public:
llist(){
rank = -1;
next = NULL;
}
int getRank(){
return rank;
}
llist* getNext(){
return next;
}
void setRank(int priority){
rank = priority;
}
void setNext(llist * n){
next = n;
}
};
llist* insert(llist* , int);
int main()
{
llist* head = NULL, *temp1 = NULL ,*last = NULL, *curr = NULL;
ifstream fin;
char str[20] = {''}, ch = ' ';
int i = 1;
fin.open("OBCarall.dat", ios::in);
int rank = -1;
while(fin >> str){
head = insert(head,atoi(str));
}
if(head == NULL)
return -1;
temp1 = last = head;
while(last->getNext() != NULL){
last = last->getNext();
}
curr = head;
while(last->getNext() != curr){
temp1 = curr;
while(temp1->getNext() != last){
temp1 = temp1->getNext();
}
cout<< curr->getRank() << " " << last->getRank() << "; " ;
curr = curr->getNext();
last = temp1;
}
/*
temp = head;
while(temp != NULL){
cout << temp->getRank() << " ";
temp = temp->getNext();
}
cout<<endl;
*/
fin.close();
return 0;
}
llist* insert(llist* head , int rank)
{
llist* temp = NULL, *trav1 = NULL,* trav2 = NULL;
int r =-1;
if(head == NULL){
head = new llist();
head->setRank(rank);
return head;
}
temp = new llist();
temp->setRank(rank);
trav2 = trav1 = head;
while(trav2 != NULL){
r = trav2->getRank();
if(r < rank){
trav1 = trav2;
trav2 = trav2->getNext();
}
else if( r > rank){
break;
}
}
if(trav2 == head){
temp->setNext(head);
head = temp;
}
else{
trav1->setNext(temp);
temp->setNext(trav2);
}
return head;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.