CREATE GRAPH WITH NEW TECHNOLOGY OF DRAWING

源代码在线查看: dfs.cpp

软件大小: 3 K
上传用户: justsohappy
关键词: TECHNOLOGY DRAWING CREATE GRAPH
下载地址: 免注册下载 普通下载 VIP

相关代码

				int getHeadProp(Node *Graphptr, Node *ptr, char prop)
				{
					int retProp;
					Node *temp;
					
					temp = findHnode(ptr, Graphptr);
					
					switch(prop)
					{
						case 'c' :
							retProp = temp -> color;
							break;
				
						case 'd' :
							retProp = temp -> di;
							break;
				
						case 'f' :
							retProp = temp -> fi;
							break;
				
						case 'v' :
							retProp = temp -> visited;
					}
					
					return retProp;
				}
				
				void setHeadProp(Node *Graphptr, Node *ptr, char prop, int setVal)
				{
					Node *temp;
				
					temp = findHnode(ptr, Graphptr);
				
					switch(prop)
					{
						case 'c' :
							temp -> color = setVal;
							break;
				
						case 'd' :
							temp -> di = setVal;
							break;
				
						case 'f' :
							temp -> fi = setVal;
							break;
				
						case 'v' :
							temp -> visited = setVal;
							break;
					}
				}
				
				Node *findHnode(Node *ptr, Node *Graphptr)
				{
					Node *temp = Graphptr;
				
					while (temp)
					{
						if (temp -> data == ptr -> data)
							break;
						temp = temp -> NbH;
					}
				
					return temp;
				}
				
				void dfs(Node *ptr)
				{
					while (ptr)
					{
						if (getHeadProp(Graphptr, ptr, 'v') == 0)
						{
							printf("%-2c", ptr -> data);
							setHeadProp(Graphptr, ptr, 'v', 1);
							dfs(findHnode(ptr -> NbN, Graphptr));			
						}
						ptr = ptr -> NbN;
					}
				}
				
				void main()
				{
					Node *Graphptr, *ptr;
					
					Graphptr = createGraph();
					ptr = Graphptr;
				
					dfs(ptr);
				}			

相关资源