Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C++ not printing out the starting Vertex of the unvisited vertices.
New Posts  All Forums:Forum Nav:

C++ not printing out the starting Vertex of the unvisited vertices.

post #1 of 3
Thread Starter 
Code:
    template<class vType, int size>
    void GraphType<vType, size>::bfs(vType startVertex)
    {
            LinkedQueueType<int> q;
     
            bool *markedVert = new bool[gSize-1];
     
            for(int i = 0; i < gSize; ++i)
                    markedVert[i] = false;
     
     
            vType vertex = startVertex;
            markedVert[vertex] = true;
           
            cout << "Starting Vertex " << vertex << " - " << vertex << " ";
     
            int idx = 0;
            vType* successor = new vType[gSize-1];
            int length = 0;
            bool done = false;
     
            while(!done && idx < gSize)
            {
                    graph[vertex].getAdjacentVertices(successor, length);
     
                    for(int i = 0; i < length; ++i)
                    {
                            if(markedVert[successor[i]] == false)
                            {
                                    q.addQueue(successor[i]);
                                    markedVert[successor[i]] = true;
                            }
                    }
     
                    if(!q.isEmptyQueue())
                    {
                            vertex = q.front();
                            cout << vertex << " ";
                            q.popQueue();
                    }
                    else
                    {
                           
                            for(int i = 0; i < gSize; ++i)
                            {
                                    if(markedVert[i] == false)
                                    {
                                            graph[i].getAdjacentVertices(successor, length);
           
                                            for(int j = 0; j < length; ++j)
                                            {
                                                    if(length == 0)
                                                    {
                                                            ++i;
                                                    }
                                                    else if(markedVert[successor[j]] == false)
                                                    {
                                                            q.addQueue(successor[j]);
                                                            markedVert[successor[j]] = true;
                                                           
                                                    }
                                            }
                                    }
                            }
                            if(q.isEmptyQueue())
                            {
                                    done = true;
                            }
                    }
            }
    }
Example: 9 4 7 3 10 8 was the output for Starting Vertex 9 and it stops @ 8 because one of the vertex didn't have a successor so the queue ended up being empty.

the remaining vertex are 0 1 2 5 6. after hitting the else statement the final output is

9 4 7 3 10 8 < 0 suppose to go here because it the starting vertex> 1 5 2 6

so im kinda bummed out cause i think it like some small thing i overlooked to get the starting vertex printed out.
Precious 2.0
(15 items)
 
My precious
(16 items)
 
 
CPUMotherboardGraphicsRAM
R7 1700 @ 3.9 | 1.35v Asus VI Crosshair Hero EVGA Titan X Hybrid 1514/2000 32GB Gskill DDR4 3200 TridentZ 
Hard DriveOptical DriveCoolingOS
Samsung 840PRO 256GB LG 10x Blu-ray Burner Swiftech H220-X Window 8.1 Professional 64Bit 
MonitorMonitorKeyboardPower
Crossover 27inch Acer XB270HU 144Hz G-Sync Deck Legend tactile frost EVGA G2 750W 
CaseMouseAudio
Coolmaster Haf 932 DeathAddder 3.5 Black edition Titanium HD | O2 DAC + AMP 
CPUMotherboardGraphicsRAM
Intel i7-970 @ 4.2 Asus Rampage Formula III Asus DC2 R9 290X @ 1110 24GB of Samsung DDR3 @ 1866 
Hard DriveOptical DriveCoolingOS
Samsung 840PRO 256GB | 2x Samsung F4 2TB | WD 6... LG 10x Blu-ray Burner H70 with 2x GT2150 Window 8.1 Professional 64Bit 
MonitorKeyboardPowerCase
Dell 2407WHFP-HC and Crossover 27Q LED-P Deck Legend tactile frost Seasonic 700watt M12 Coolmaster Haf 932 
MouseMouse PadAudioAudio
DeathAddder 3.5 Black edition TeamLiquid Goliathus Titanium HD AudioEngine A2 and ATH-700D 
CPUGraphicsRAMHard Drive
Intel - 3630QM Nvidia GTX 680M 8 GB DDR3 1600 500GB 7200 | 128 GB Samsung 840 Pro 
Optical DriveOS
DVD RW  Windows 8 Pro 
  hide details  
Reply
Precious 2.0
(15 items)
 
My precious
(16 items)
 
 
CPUMotherboardGraphicsRAM
R7 1700 @ 3.9 | 1.35v Asus VI Crosshair Hero EVGA Titan X Hybrid 1514/2000 32GB Gskill DDR4 3200 TridentZ 
Hard DriveOptical DriveCoolingOS
Samsung 840PRO 256GB LG 10x Blu-ray Burner Swiftech H220-X Window 8.1 Professional 64Bit 
MonitorMonitorKeyboardPower
Crossover 27inch Acer XB270HU 144Hz G-Sync Deck Legend tactile frost EVGA G2 750W 
CaseMouseAudio
Coolmaster Haf 932 DeathAddder 3.5 Black edition Titanium HD | O2 DAC + AMP 
CPUMotherboardGraphicsRAM
Intel i7-970 @ 4.2 Asus Rampage Formula III Asus DC2 R9 290X @ 1110 24GB of Samsung DDR3 @ 1866 
Hard DriveOptical DriveCoolingOS
Samsung 840PRO 256GB | 2x Samsung F4 2TB | WD 6... LG 10x Blu-ray Burner H70 with 2x GT2150 Window 8.1 Professional 64Bit 
MonitorKeyboardPowerCase
Dell 2407WHFP-HC and Crossover 27Q LED-P Deck Legend tactile frost Seasonic 700watt M12 Coolmaster Haf 932 
MouseMouse PadAudioAudio
DeathAddder 3.5 Black edition TeamLiquid Goliathus Titanium HD AudioEngine A2 and ATH-700D 
CPUGraphicsRAMHard Drive
Intel - 3630QM Nvidia GTX 680M 8 GB DDR3 1600 500GB 7200 | 128 GB Samsung 840 Pro 
Optical DriveOS
DVD RW  Windows 8 Pro 
  hide details  
Reply
post #2 of 3
Thread Starter 
=( ?
Precious 2.0
(15 items)
 
My precious
(16 items)
 
 
CPUMotherboardGraphicsRAM
R7 1700 @ 3.9 | 1.35v Asus VI Crosshair Hero EVGA Titan X Hybrid 1514/2000 32GB Gskill DDR4 3200 TridentZ 
Hard DriveOptical DriveCoolingOS
Samsung 840PRO 256GB LG 10x Blu-ray Burner Swiftech H220-X Window 8.1 Professional 64Bit 
MonitorMonitorKeyboardPower
Crossover 27inch Acer XB270HU 144Hz G-Sync Deck Legend tactile frost EVGA G2 750W 
CaseMouseAudio
Coolmaster Haf 932 DeathAddder 3.5 Black edition Titanium HD | O2 DAC + AMP 
CPUMotherboardGraphicsRAM
Intel i7-970 @ 4.2 Asus Rampage Formula III Asus DC2 R9 290X @ 1110 24GB of Samsung DDR3 @ 1866 
Hard DriveOptical DriveCoolingOS
Samsung 840PRO 256GB | 2x Samsung F4 2TB | WD 6... LG 10x Blu-ray Burner H70 with 2x GT2150 Window 8.1 Professional 64Bit 
MonitorKeyboardPowerCase
Dell 2407WHFP-HC and Crossover 27Q LED-P Deck Legend tactile frost Seasonic 700watt M12 Coolmaster Haf 932 
MouseMouse PadAudioAudio
DeathAddder 3.5 Black edition TeamLiquid Goliathus Titanium HD AudioEngine A2 and ATH-700D 
CPUGraphicsRAMHard Drive
Intel - 3630QM Nvidia GTX 680M 8 GB DDR3 1600 500GB 7200 | 128 GB Samsung 840 Pro 
Optical DriveOS
DVD RW  Windows 8 Pro 
  hide details  
Reply
Precious 2.0
(15 items)
 
My precious
(16 items)
 
 
CPUMotherboardGraphicsRAM
R7 1700 @ 3.9 | 1.35v Asus VI Crosshair Hero EVGA Titan X Hybrid 1514/2000 32GB Gskill DDR4 3200 TridentZ 
Hard DriveOptical DriveCoolingOS
Samsung 840PRO 256GB LG 10x Blu-ray Burner Swiftech H220-X Window 8.1 Professional 64Bit 
MonitorMonitorKeyboardPower
Crossover 27inch Acer XB270HU 144Hz G-Sync Deck Legend tactile frost EVGA G2 750W 
CaseMouseAudio
Coolmaster Haf 932 DeathAddder 3.5 Black edition Titanium HD | O2 DAC + AMP 
CPUMotherboardGraphicsRAM
Intel i7-970 @ 4.2 Asus Rampage Formula III Asus DC2 R9 290X @ 1110 24GB of Samsung DDR3 @ 1866 
Hard DriveOptical DriveCoolingOS
Samsung 840PRO 256GB | 2x Samsung F4 2TB | WD 6... LG 10x Blu-ray Burner H70 with 2x GT2150 Window 8.1 Professional 64Bit 
MonitorKeyboardPowerCase
Dell 2407WHFP-HC and Crossover 27Q LED-P Deck Legend tactile frost Seasonic 700watt M12 Coolmaster Haf 932 
MouseMouse PadAudioAudio
DeathAddder 3.5 Black edition TeamLiquid Goliathus Titanium HD AudioEngine A2 and ATH-700D 
CPUGraphicsRAMHard Drive
Intel - 3630QM Nvidia GTX 680M 8 GB DDR3 1600 500GB 7200 | 128 GB Samsung 840 Pro 
Optical DriveOS
DVD RW  Windows 8 Pro 
  hide details  
Reply
post #3 of 3
It won't print 0 because 0 cannot be greater than itself(Someone correct me if I'm wrong, I just started learning Java five days ago)
Po' Pimpin'
(11 items)
 
  
CPUMotherboardRAMHard Drive
i5 2500k @ stock Biostar TZ68K+ [A3] 4GB  Sandforce 1222 64GB SSD 
Optical DriveCoolingOSMonitor
LG 22x DVD-+RW  Stock Windows 7 x64 Acer S211HL 1080p 
PowerCaseMouse
600w Diablotek Linkworld Electronic Inland 
  hide details  
Reply
Po' Pimpin'
(11 items)
 
  
CPUMotherboardRAMHard Drive
i5 2500k @ stock Biostar TZ68K+ [A3] 4GB  Sandforce 1222 64GB SSD 
Optical DriveCoolingOSMonitor
LG 22x DVD-+RW  Stock Windows 7 x64 Acer S211HL 1080p 
PowerCaseMouse
600w Diablotek Linkworld Electronic Inland 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C++ not printing out the starting Vertex of the unvisited vertices.