void EDIT( )
{  
	STACK S;    char c ;
	MAKENULL ( S );
	cin.get(c) ;
	while ( c != '\n' )
	{ 
		if ( c == '#' )
			POP ( S );
		else if ( c == '@' )
			MAKENULL ( S );
		else 
			PUSH ( c , S );
		cin.get(c) ;
    }
	while(!EMPTY(S))
	{
		cout<<TOP(S);
		POP(S);
	}
	cout<<endl;   
}
boolean Correct(char ext[], int n)
{
	STACK S;
	char x;
	int j=0;
	MAKENULL(S);
	while(ext[j])
	{
		if(ext[j]=='(')
			PUSH('(', S);
		else if(ext[j]==')')
		{
			x=TOP(S);
			if(x=='(')
				POP(S);
			else
				return FALSE;
		}
		j++;
	}
	if(!EMPTY(S)) 
		return FALSE;
	else
		return TRUE;
}
Пример #3
0
main() {
	LIST L, p, p2;
	char ans, element;

	MAKENULL(&L);

	do {
		clrscr();
		printf("\n	MENU\n");
		printf("[1] Insert\n");
		printf("[2] Delete\n");
		printf("[3] Display\n");
		printf("[4] Search\n");
		printf("[5] Quit\n\n");
		printf("Enter chosen number: ");
		ans = toupper(getche());
		switch (ans) {
			case '1':
				/* case 1 has an approximated running time of 3n + 12 */
				printf("\n\nEnter an element to insert: ");
				element = getche();
				p = INS_POS(element, L);
				INSERT(element, p);
				break;
			case '2' :
				/* case 2 has an approximated running time of 8n + 10 */
				printf("\n\nEnter element to delete: ");
				element = getche();
				p = LOCATE(element,L);
				DELETE(element, p);
				break;
			case '3' :
				/* case 3 has an approximated running time of 3n + 4 */
				printf("\n\n");
				PRINTLIST(L);
				break;
			case '4' :
				/* case 4 has an approximated running time of 4n + 14 */
				printf("\n\nEnter element to search: ");
				element = getch();
				p = LOCATE(element,L);
				SEARCH(element, p);
				break;
			case '5' :
				break;
		}
	} while (ans != '5');
	DELETEALL(p); /* DELETEALL has an approximated runnning time of 4n + 1 */
}
void Topologicalsort( AdjGraph G, int aov[NumVertices] )
{  
	int v, w, nodes;
	EdgeNode *tmp;
	EdgeData indegree[NumVertices+1]={0};

	QUEUE Q ;
	MAKENULL( Q ) ;

	// 计算每个顶点的入度
	for( v=1; v<=G.n ; ++v )
	{
		tmp=G.vexlist[v].firstedge;
		while(tmp)
		{
			indegree[tmp->adjvex]++;
			tmp=tmp->next;
		}	
	}
	// 将入度为0的顶点加入队列
	for(v=1; v<=G.n; ++v)
		if ( indegree[v] ==0 ) 
			ENQUEUE( v, Q ) ;
	
	nodes = 0 ;
	while ( !EMPTY( Q ) )
	{  
		v = FRONT(Q)->element ;
		DEQUEUE( Q ) ;
		//cout << v <<' '; 
		aov[nodes]=v;
		nodes ++ ;		// 已考虑的节点个数加1
		// 如果(v, w)是一条边,将w的入度减1,如果w的入度为0,则将w入队
		for( w=1; w<=G.n; w++) 
		{
			if(connect(G, v, w))
			{
				--indegree[w];
				if( !(indegree[w])) 
					ENQUEUE(w,Q) ;
			}
		}
	}
	cout<<endl;
	if ( nodes < G.n ) 
		cout<<"图中有环路"<<endl;
	
}