Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------- exercício 4 -------------------------------------------------------
- #include <stdio.h>
- #include <windows.h>
- #include <conio.h>
- #include <string.h>
- struct Estrutura{
- int chave;
- char nome[45];
- };
- struct LISTA{
- Estrutura * estrutura;
- LISTA * prox;
- };
- LISTA * insere_inicio(LISTA * inicio){
- LISTA * aux;
- LISTA * novo = new LISTA();
- novo -> estrutura = new Estrutura();
- printf("Informe a Chave ");
- scanf("%d", & novo -> estrutura -> chave);
- printf("Informe a Nome ");
- scanf("%s", & novo -> estrutura -> nome);
- //se a lista for vazia � o primeiro no
- if(inicio == NULL){
- inicio = novo;
- inicio -> prox = NULL;
- }else{
- novo -> prox = inicio;
- inicio = novo;
- }
- return inicio;
- }
- void imprime_lista(LISTA * inicio){
- if(inicio == NULL){
- printf("A lista esta vazia ");
- }else{
- LISTA * aux;
- aux = inicio;
- // enquanto a lista nao for vazia
- while(aux != NULL){
- printf("\nChave: %d Nome:%s", aux -> estrutura -> chave, aux -> estrutura -> nome);
- aux = aux -> prox;
- }
- }
- }
- void busca_lista( LISTA * inicio){
- int a,achou=0;
- char nome[45];
- if(inicio == NULL){
- printf("A lista esta vazia");
- }else{
- LISTA * aux;
- aux = inicio;
- printf("Informe a Chave: ");
- scanf("%d", &a);
- while(aux != NULL){
- if(a == aux -> estrutura -> chave){
- printf("Nome: %s", aux->estrutura->nome);
- achou= 1;
- }
- aux = aux -> prox;
- }
- if(achou == 0){
- printf("N�o foi encontrado");
- }
- }
- }
- LISTA * remove (LISTA * inicio){
- int b,achou=0;
- LISTA * aux;
- LISTA * anterior;
- if(inicio == NULL){
- printf("A lista esta vazia");
- }else{
- aux = inicio;
- anterior = inicio;
- printf("Informe a Chave: ");
- scanf("%d", &b);
- while(aux != NULL){
- if(b == aux -> estrutura -> chave){
- if(aux == inicio){
- inicio = aux -> prox;
- delete(aux);
- aux = inicio;
- }else{
- anterior -> prox = aux -> prox;
- delete(aux);
- aux = anterior -> prox;
- }
- achou++;
- }else{
- anterior = aux;
- aux = aux -> prox;
- }
- }
- if(achou == 0){
- printf("\nnao foi encontrado");
- }else{
- printf("\nRemovido %d vezes",achou);
- }
- }
- return inicio;
- }
- int main(){
- LISTA * inicio = NULL;
- int menu;
- do{
- system("cls");
- printf("menu de opcoes");
- printf("\n1 - Inserir");
- printf("\n2- Consultar");
- printf("\n3- Buscar");
- printf("\n4- Remover");
- printf("\n5- Sair");
- printf("\nDigite o opcao desejada ");
- scanf("%d", &menu);
- switch(menu){
- case 1:
- inicio = insere_inicio(inicio);
- break;
- case 2:
- imprime_lista(inicio);
- break;
- case 3:
- busca_lista(inicio);
- break;
- case 4:
- inicio = remove(inicio);
- break;
- }
- getch();
- }while(menu !=4);
- }
- ----------------------------------------------- exercício 5 -----------------------------------------------------------------
- #include <stdio.h>
- #include <windows.h>
- #include <conio.h>
- #include <string.h>
- #include <stdlib.h>
- struct Estrutura{
- int nota;
- char nome[45];
- };
- struct LISTA{
- Estrutura * estrutura;
- LISTA * prox;
- };
- LISTA * insere_nota(LISTA * inicio){
- LISTA * aux;
- LISTA * novo = new LISTA();
- novo -> estrutura = new Estrutura();
- printf("Informe a Nome ");
- scanf("%s", & novo -> estrutura -> nome);
- printf("Informe a nota final: ");
- scanf("%d", & novo -> estrutura -> nota);
- if(inicio == NULL){
- inicio = novo;
- inicio -> prox = NULL;
- }else{
- novo -> prox = inicio;
- inicio = novo;
- }
- return inicio;
- }
- void imprime_lista(LISTA * inicio)
- {
- if (inicio != NULL)
- {
- if (inicio->estrutura->nota>=7){
- printf("\nNome: %s ", inicio->estrutura->nome);
- printf("Nota: %d ", inicio->estrutura->nota);
- }
- imprime_lista(inicio->prox);
- }
- }
- int main (){
- LISTA * inicio = NULL;
- for (int i; i<5; i++){
- inicio = insere_nota(inicio);
- }
- system("cls");
- imprime_lista(inicio);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement