Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <conio.h>
- struct Vertice
- {
- char label;
- struct Vertice *prox;
- };
- typedef struct Vertice v[10];
- void MudarCor(int cor);
- void CriarVert(struct Vertice **v);
- struct Vertice* Criar(char label);
- struct Vertice* Criar(char label);
- int checarLink(struct Vertice **l, char p, char s);
- struct Vertice * inserir(struct Vertice **l, char p, char s, int pos);
- void imprimir(struct Vertice **l);
- int cores[10] = {1,2,3,4,5,6,7,8,9,10};
- int tam = 10;
- /*void alocar(v *vertices[10], int tam);
- void alocar(v *vertices[10], int tam)
- {
- tam = 10;
- int i, w = 0;
- *vertices= (v*)malloc(sizeof(v));
- for(i=0; i<tam; i++)
- {
- vertices[i]->label = (char *)malloc(tam*sizeof(char));
- vertices[i]->prox = NULL;
- w++;
- }
- }
- */
- int main()
- {
- int i;
- struct Vertice *l[tam];
- for(i=0; i<tam; i++)
- {
- l[i] = (struct Vertice*)malloc(sizeof(struct Vertice));
- l[i]->label = 'a';
- l[i]->prox = NULL;
- }
- l[1]->label = 'A';
- CriarVert(l);
- MudarCor(2);
- // inserirVertice();
- // inserirAresta();
- printf("eeeeaaaeee\n");
- return 0;
- }
- void CriarVert(struct Vertice **v)
- {
- int i, op;
- char d, p, s;
- i=0;
- printf("\n1- Para adicionar um vertice\n2- Para adicionar ligacao\n3- Para imprimir\n");
- scanf("%d", &op);
- while (op == 1)
- {
- printf("Digite o rotulo\n");
- d = getche();
- v[i] = Criar(d);
- i++;
- printf("\n1- Para adicionar um vertice\n2- Para adicionar ligacao\n");
- scanf("%d", &op);
- }
- while(op == 2)
- {
- printf("\nDigite o primeiro rotulo da ligacao: ");
- p = getche();
- printf("\nDigite o segundo rotulo da ligacao: ");
- s = getche();
- checarLink(v, p, s);
- printf("\n1- Para adicionar um vertice\n2- Para adicionar ligacao\n");
- scanf("%d", &op);
- }
- while(op == 3)
- {
- imprimir(v);
- printf("\n1- Para adicionar um vertice\n2- Para adicionar ligacao\n");
- scanf("%d", &op);
- }
- }
- int checarLink(struct Vertice **l, char p, char s)
- {
- int i, checkP = 0, checkS = 0, posP = 0, posS = 0;
- for(i=0; i<tam; i++)
- {
- while(l[i] != NULL)
- {
- if(l[i]->label == p)
- {
- checkP = 1;
- posP = i;
- break;
- }
- if(l[i]->label == s)
- {
- checkS = 1;
- posS = i;
- break;
- }
- }
- }
- if(checkS == 1 && checkP == 1)
- {
- inserir(l, p, s, posP);
- inserir(l, s, p, posS);
- }
- else if(checkS == 0)
- {
- return printf("\nSegundo rotulo nao encontrado!\n");
- }
- else if(checkP == 0)
- {
- return printf("\nPrimeiro rotulo nao encontrado!\n");
- }
- else if(checkS == 0 && checkP == 0)
- {
- return printf("\nOs rotulos nao foram encontrados!\n");
- }
- return 0;
- }
- struct Vertice * inserir(struct Vertice **l, char p, char s, int pos)
- {
- int i;
- struct Vertice *novo[tam];
- struct Vertice *atual[tam];
- if (l[pos]==NULL)
- {
- *novo = (struct Vertice*)malloc(sizeof (struct Vertice));
- for(i=0; i<tam; i++)
- {
- novo[i] = NULL;
- }
- novo[pos]->label= p;
- novo[pos]->prox = NULL;
- l[pos] = novo[pos];
- }
- else
- {
- for(i=0; i<tam; i++)
- {
- atual[i] = (struct Vertice*)malloc(sizeof(struct Vertice));
- atual[i]->label = 'a';
- atual[i]->prox = NULL;
- }
- *atual[pos] = *l[pos];
- while(atual[pos]->prox != NULL)
- {
- atual[pos] = atual[pos]->prox;
- }
- atual[pos]->label = p;
- *l[pos] = *atual[pos];
- }
- return *l;
- }
- void imprimir(struct Vertice **l)
- {
- int i = 0, j = 0;
- struct Vertice *p[tam];
- for(i=0; i<tam; i++)
- {
- p[i] = (struct Vertice*)malloc(sizeof(struct Vertice));
- p[i]->label = 'a';
- p[i]->prox = NULL;
- }
- i=0;
- for(j=0; j<tam; j++)
- {
- printf("\n%d.o vertice %c ->", j + 1, p[j]->label);
- for(p[j] = l[j]; p[j] != NULL; p[j] = p[j]->prox)
- {
- printf("\t%c\n", p[j]->label);
- }
- }
- system("pause");
- }
- struct Vertice* Criar(char label)
- {
- int i;
- struct Vertice* novo = malloc(sizeof(struct Vertice));
- novo->label = label;
- for (i = 0; i < 10; i++)
- novo->prox = NULL;
- return novo;
- }
- void MudarCor(int cor)
- {
- HANDLE hOut;
- hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hOut, cor);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement