Thread: Help would be appreciated

  1. #1
    Registered User
    Join Date
    May 2016
    Posts
    2

    Help would be appreciated

    Hello, Iíve got an assignment from my math teacher to do with c++, because I am studying IT. The problem is that we didnít even learn c++, I know only what I thought myself, so I need someoneís help. The task is to make a simple program that would be able to find an answer for greedy coloring method. I have a graph G, the answer should look something like this: 1, 3, 5, 6 belong to color 3; 4, 8 belong to color 2; 2, 6 belong to color 1. Imgur: The most awesome images on the Internet Can someone help me with this? I found some source code on the internet but I need much more simple code, so I would be able to explain what is happening in the program.

    Graph: Imgur: The most awesome images on the Internet

  2. #2
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by dilan548 View Post

    I know only what I thought myself, so I
    You mean taught ?

    Quote Originally Posted by dilan548 View Post

    I found some source code on the internet but I need much more simple code, so I would be able to explain what is happening in the program.
    This is quite frankly not acceptable. You have to come here and show us how you, yourself have tried to solve the problem then we will help you go ahead - now what you found on google or what someone else wrote.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,508
    Here too.

  4. #4
    Registered User
    Join Date
    May 2016
    Posts
    2
    //So far I got this:
    Code:
    #include <iostream>
    #include <conio.h>
    
    const int R = 8;
    const int C = 4;
    
    int safe(int a, int G[R][C], int color[], int c);
    int checking(int G[R][C], int m, int color[], int a);
    void graphcoloring(int G[R][C], int m);
    void coloring(int color[]);
    
    using namespace std;
    
    int main()
    {
        int G[R][C] = {
                { 2, 8, 0, 0 },
                { 1, 3, 4, 8 },
                { 2, 4, 0, 0 },
                { 2, 3, 5, 6 },
                { 4, 6, 0, 0 },
                { 4, 5, 7, 0 },
                { 6, 8, 0, 0 },
                { 1, 2, 7, 0 } };
        int m = 3; //colors
        graphcoloring(G, m);
        _getch();
    }
    int safe(int a, int G[R][C], int color[], int c)
    {
        for (int i = 0; i < R; i++)
        {
            if (G[R][i] && c == color[i])
                return 0;
            else
                return 1;
        }
    }
    int checking(int G[R][C], int m, int color[], int a)
    {
        int c;
        if (a == R)
            return 1;
        for (c = 1; c <= m; c++)
        {
            if (safe(a, G, color, c))
            {
                color[a] = c;
                if (checking(G, m, color, a + 1) == 1)
                    return 1;
                else
                    color[a] = 0;
            }
        }
    }
    void graphcoloring(int G[R][C], int m)
    {
        int color[R];
        for (int i = 0; i < R; i++)
            color[i] = 0;
        if (checking(G, m, color, 0) == 0)
        {
            cout << "Can't color";
            return;
        }
        coloring(color);
    }
    void coloring(int color[])
    {
        cout << "The colors are: " << endl;
        for (int i = 0; i < R; i++)
            cout << color[i] << endl;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hello, I need your help. Any help is appreciated.
    By angico_211 in forum C Programming
    Replies: 11
    Last Post: 06-22-2011, 08:05 AM
  2. Need help, would be very appreciated.
    By DK12 in forum C Programming
    Replies: 16
    Last Post: 07-28-2009, 04:54 PM
  3. Little help will be appreciated
    By nicolassp in forum C Programming
    Replies: 18
    Last Post: 06-24-2009, 06:57 AM
  4. Help would be much appreciated.
    By jitterbug in forum C++ Programming
    Replies: 6
    Last Post: 04-01-2009, 08:02 PM
  5. much appreciated
    By razrektah in forum C++ Programming
    Replies: 3
    Last Post: 09-14-2001, 10:14 AM

Tags for this Thread