Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:17:37+00:00 2026-06-03T02:17:37+00:00

I’m attempting to code Prim’s algorithm. However when I compile I get errors on

  • 0

I’m attempting to code Prim’s algorithm. However when I compile I get errors on lines: 57,59,60,62,63,65

Obviously it was something to do with my arrays… I just don’t know what exactly. I get the feeling it has to do with pointers which I have tried to figure out and have failed.

int map[][7] is a global array I am using to keep track of my initial graph.

edit – as requested here is all of the code

#include <iostream>

using namespace std;

void performPrims(int);
void print(int *);

// Global Variables
int nodes = 7;
int cur   = 0;
int cost  = 0;

int map[][7] =  
   {{0,3,6,0,0,0,0},
    {3,0,7,0,0,12,0},
    {6,7,0,10,13,8,0},
    {0,0,10,0,0,0,5},
    {0,0,13,0,0,9,4},
    {0,12,8,0,9,0,11},
    {0,0,0,5,4,11,0}};

int main()
{
// Initializations

srand(time(NULL)); 
int S = rand() % 7; // Create an arbitrary starting point

// Perform Prim's Algorithm starting with S

performPrims(S);

return 0;
}

void performPrims(int S)
{
int low = 100;

// open[] is used to keep track of what vertices are available
int open [] = {1,2,3,4,5,6,7};

// closed [] is used to keep track of what vertices have been reached and in what order
int closed [] = {0,0,0,0,0,0,0};

open [S] = 0;       // Make our starting node unavailable
closed [cur] = S+1; // Record our starting node in the path
cur++;

while (cur < 7)
{
    int i=0;
    while (i<nodes)
    {
        int k=0;
        while (k<nodes)
        {
            if (*map[*close[i]-1][k] > 0 && *map[*close[i]-1][k] < low)
            {
                low = map[close[i]-1][k];
                close [cur] = k+1;
            }
            map[close[cur-1]-1][close[cur]-1] = 0;
            map[close[cur]-1][close[cur-1]-1] = 0;
            cost += low; low = 100;
            open[close[cur]-1] = 0;
            k++;
        }
        i++;
    }
    cur++;
}
print(closed);
}

void print(int *closed)
{
cout<<"The path taken was ";
for (int i=0; i<nodes; i++)
    cout<<closed[i]<<" "<<endl;
cout<<"\nThe cost is "<<cost<<endl;
}

Errors

There are a few different ones:

error: pointer to a function used in arithmetic (Many Lines)
error: invalid types ‘int[7][7][int (*)(int)]’ for array subscript (Many Lines)
error: assignment of read-only location (LINE 60)
error: cannot convert ‘int’ to ‘int ()(int)’ in assignment (LINE 60)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:17:38+00:00Added an answer on June 3, 2026 at 2:17 am

    You misspelled closed. You typed close instead.

    Replace all instances of close with closed.

    Also, add #include <cstdlib> to the top of the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.