kalo93

Untitled

Feb 3rd, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include <stdlib.h>
  4. #include <locale.h>
  5. #include <windows.h>
  6. #define MAX 200
  7.  
  8. typedef struct cel{
  9. int cod;
  10. char nome[MAX];
  11. struct cel *prox;
  12. }celula;
  13.  
  14. celula *ini = NULL;
  15.  
  16. void imprima( )
  17. {
  18. system("cls");
  19. if (ini == NULL)
  20. {
  21. printf("\nLista vazia.\n");
  22. getch();
  23. return;
  24. }
  25. celula *p;
  26. printf("\n Itens na lista: ");
  27. for (p = ini; p != NULL; p = p->prox)
  28. printf( "%d ", p->cod);
  29. getch();
  30. }
  31.  
  32. celula *busca(celula *ini)
  33. {
  34. system("cls");
  35. int x=0;
  36. printf("numero");
  37. scanf("%d",&x);
  38. celula *p;
  39. p = ini->prox;
  40. while (p != NULL && p->cod != x)
  41. p=p->prox;
  42. return p;
  43. }
  44.  
  45. void insere()
  46. {
  47. system("cls");
  48. int x;
  49. char nome(MAX);
  50. printf("numero: ");
  51. scanf("%d",&x);
  52.  
  53. celula *nova = (celula*)malloc (sizeof (celula));
  54. nova->cod = x;
  55. nova->prox = ini;
  56. ini = nova;
  57. printf("nome: ");
  58. scanf("%s",&nome);
  59. nova->nome[MAX]= nome;
  60. nova->prox = ini;
  61. ini = nova;
  62.  
  63. printf("numero %d inserido.\n",x);
  64. getch();
  65. }
  66.  
  67. void remove()
  68. {
  69. if (ini == NULL)
  70. {
  71. printf("\nLista vazia. Sem itens para remover.\n");
  72. getch();
  73. return;
  74. }
  75.  
  76. else
  77. {
  78. celula *remove = ini;
  79. ini = remove->prox;
  80. printf("\nitem %d removido.\n",remove->cod);
  81. free(remove);
  82. getch();
  83. }
  84. }
  85.  
  86. void menu() {
  87. system("cls");
  88. printf(" Menu ");
  89. printf("\n*********************************");
  90. printf("\n* 1-Inserir *");
  91. printf("\n* 2-Listar *");
  92. printf("\n* 3-buscar *");
  93. printf("\n* 4-remove *");
  94. printf("\n* 5-alterar *");
  95. printf("\n* 6-inserir no fim *");
  96. printf("\n* 0-sair *");
  97. printf("\n*********************************\n");
  98. printf("Entre com a opcao desejada: ");
  99. }
  100.  
  101. int main(){
  102. char op;
  103. do {
  104. menu();
  105. op=getche();
  106. switch(op) {
  107. case '1': insere();
  108. break;
  109. case '2': imprima();
  110. break;
  111. case '3': busca(ini);
  112. break;
  113. case '4': remove();
  114. break;
  115.  
  116. }
  117.  
  118. } while (op != '0');
  119. return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment