Jump to content

Data structure arrays

Maybe once you have gone through it and coded it as per the instructions it will make sense to you?

If you're interested in a product please download and read the manual first.

Don't forget to tag or quote in your reply if you want me to know you've answered or have another question.

Link to comment
Share on other sites

Link to post
Share on other sites

11 minutes ago, ShahNawaz chaudhary said:

Can you please implement this is a C program ?

Nobody on this forum is going to do your homework for you.

~Air Cooling Advocate~

Link to comment
Share on other sites

Link to post
Share on other sites

void swap(int *a, int *b);
 
void sort012(int a[], int arr_size)
{
    int lo = 0;
    int hi = arr_size - 1;
    int mid = 0;
  
    while (mid <= hi)
    {
        switch (a[mid])
        {
        case 0:
            swap(&a[lo++], &a[mid++]);
            break;
        case 1:
            mid++;
            break;
        case 2:
            swap(&a[mid], &a[hi--]);
            break;
        }
    }
}
Link to comment
Share on other sites

Link to post
Share on other sites

In your 2nd post you started to code as they specified. Not to hard really they've practically written it all for you. Obviously N isn't a number though. What could N represent? But then that code is missing from your last solution, and you change conditions they give, eg...

 

they say

while (y < r+1)

yet for some reason you change it to

while (mid <= hi)

 

BTW learn to use code tags for code, and reply to or tag users so they know the thread has new posts.

 

 

If you're interested in a product please download and read the manual first.

Don't forget to tag or quote in your reply if you want me to know you've answered or have another question.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×