Giter VIP home page Giter VIP logo

data_structure-in-c's Introduction

단일 연결리스트

#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct NODE { char name[21]; int grade; struct NODE *next; } NODE;

NODE *getnode(char *name, int grade) {

	NODE *newnode = (NODE *)malloc(sizeof(NODE));

	newnode->next = NULL;

	strcpy(newnode->name, name);

	newnode->grade = grade;

	return newnode;

}



int main() {

	char name[21];

	int grade;

	NODE *L = NULL, *newnode;

	NODE*ptr, *tmp;

	while (1) {

		// name 입력받고 0이면 break;

		//제일 처음이면 L== NULL일 것.
		gets_s(name);
		if (strcmp(name, "0") == 0) break;
		scanf("%d", &grade);
		getchar();
		if (L == NULL) L = getnode(name, grade);

		else {

			newnode = getnode(name, grade);

			newnode->next = L;

			L = newnode;
		}
	}

	for (ptr = L; ptr != NULL; ptr = ptr->next) {
		printf("%s %d", ptr->name, ptr->grade);
	}


	for (ptr = L; ptr != NULL; ) {

		tmp = ptr->next;

		free(ptr);

		ptr = tmp;

	}


	return 0;
}

data_structure-in-c's People

Contributors

cmoweg avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.