vendredi 5 octobre 2018

I need help in my data structure homework on stacks

ifndef Family_h

define Family_h

class Family

{

private:

int noOfKids;

int noOfElders ;

int Id;

public:

Family(int ID, int E, int K):Id(ID),noOfElders(E),noOfKids(K){};

Family(int& ID, int& E, int& K):Id(ID),noOfElders(E),noOfKids(K){};

~Family();//destructor

int getkidsn(){return this->noOfKids;}

int geteldersn(){return this->noOfElders;}

int getidn(){return this->Id;}

};

endif

include "Family.h"

include

using namespace std;

struct Counter{ Family family; int count; struct Counter*next;};

Counter*temp;

Counterbigfamilies(Countercounter1, Countercounter2) { Counterkids= nullptr, *que= nullptr;

temp = counter1;

while(temp!= nullptr){

    if(temp->family.getkidsn()> 3){

        if(kids == nullptr){kids = temp;}

        else{que = kids;}

        while(temp->next != nullptr){que=que->next;}

        que->next = temp;}}

temp = counter2;

while(temp !=nullptr){

    if(temp->family.getkidsn()> 3){

        if(kids == nullptr){kids = temp;}

        else{que = kids;}

        while(temp->next != nullptr){que=que->next;}

        que->next = temp;}}

return kids;

}

Counterfastprocess(Counter counter1, Counter* counter2){

Counter*fastprocess =nullptr;

int cc1,cc2,c3,equalcount, count;

cc1 = counter1->count;

cc2 =counter2->count;

equalcount= (cc1 +cc2)/3;

count =(cc1+ cc2)%3;

if(count == 0){cc1= cc2=c3 =equalcount;}

else if(count ==1){cc1=cc2= equalcount; c3=equalcount+1;}

else{cc1=cc2=equalcount+1; c3 = equalcount;}

Counter *c1,*c2;

c1=counter1;

c2=counter2;

while(cc1!=1){

    c1= c1->next;

    cc1--;}

temp = c1;

c1=c1->next;

temp->next = nullptr;

while(cc2 !=1){

    c2 = c2->next;

    cc2--;}

temp = c2;

c2=c2->next;

temp = nullptr;

temp= fastprocess;

while(c3){if(c1){

    if(fastprocess == nullptr){

        fastprocess = c1;

        temp = fastprocess;

        c1=c1->next;

        c3--;}

    else{

        temp->next = c1;

        c1 = c1->next;

        c3--;}}

    if(c2){

        temp->next = c2;

        c2= c2->next;

        c3--;}}

    return fastprocess;}

int main()

{

    int i,e,k;

    Counter *counter[4], *x;

    for(int i=0;i<4;i++)

    {
        counter[i] = NULL;
    }

    while(1)

    {
        cin >> i>>e>>k;

        if(i==0 && e==0 && k==0)

            break;

        Family family = new Family(i,e,k);//error

        *x= new Counter();//error

        x->family = family;

        x->next = NULL;


        if((family.getkidsn() == 0) && (family.geteldersn() == 1))

        {

            if(counter[1] == NULL)

            {
                counter[1] = x;
            }

            else

            {
                Counter *p = counter[1];

                while(p->next != NULL)

                {
                    p=p->next;
                }

                p->next = x;
            }

            counter[1]->count++;
        }

        else

        {
            if(counter[2] == NULL)

            {
                counter[2] = x;
            }

            else

            {
                Counter *p = counter[2];

                while(p->next != NULL)

                {
                    p=p->next;
                }

                p->next = x;
            }

            counter[2]->count++;
        }
    }

    Counter *bigfamilycounter = bigfamilies(counter[1],counter[2]);

    Counter *counter3 = fastprocess(counter[1], counter[2]);

    return 0;
}

i don't know how is it possible for me to fix my two errors. i know my code might seem inefficient, and not that neat.... I'm new to this

Aucun commentaire:

Enregistrer un commentaire