자료구조/by C

자료구조/by C

c언어 stack 구현

내 입맛대로 stack 구현하기 1. empty 2. push 3. pop 4. size push를 할 때 자신의 입맛대로 매개변수 만들어서 넣으시면 됩니다. node에는 해당 문제에 따라서 저장할 값을 추가적으로 넣어주시면 됩니다. #include #include typedef long long ll; typedef struct node{ char value; int cnt;//몇 개 쌓아왔는지 struct node* pre; }node; typedef struct stack{ node *top; ll size; }stack; ll size(stack* s){ return s->size; } node* top(stack*s){ return s->top; } bool empty(stack*s){ retu..

자료구조/by C

c언어 double linked list 구현

흠.. 일단 그냥 막 내가 쓰고 싶은 대로 구현하긴 했다. prev, next를 통해서 전과 후로 갈 수 있고 insert,delete가 O(1)에 해결 가능하다. insert는 여러 버전이 있는데, index에 추가하는 것과, 가리키고 있는 node에 insert하는 것과, 제일 앞에 insert, 그리고 제일 뒤에 insert을 넣는 버전이 있다. #include typedef long long ll; typedef struct node{ char value;//값 struct node* prev;//전 struct node* next;//다음 }node; typedef struct Linkedlist{ node* front;//맨 앞 node* back;//맨 뒤 ll size;//크기 }Linke..

자료구조/by C

c언어 vector 구현

c++ vector를 c언어에서도 쓰고 싶어서 간단하게 만들어 봤습니다. #include typedef long long ll; typedef struct node{//해당하는 값을 arr로 갖는다. int v; }node; typedef struct vector{//인덱스 접근 가능해야 하며, size 존재, back, pop_back, node* arr;//값을 저장하는 곳 ll size;//크기 ll capacity;//전체 크기 }vector; void init(vector *q){ q->arr=(node *)malloc(sizeof(node)*(64)); q->size=0; q->capacity=64;//초기 크기 64개 } void push_back(vector *q,int v){//v가 추가..

자료구조/by C

c언어 queue 구현

나만의 queue 구현 코드 #include #define ll long long typedef struct newtype{ int v;//자료형 새로 추가하면 된다. }newtype; typedef struct node{ struct newtype x;// struct node* next;//다음 노드 가리키기 }node; typedef struct queue{//front,pop,size,empty,push node* front;//처음에 연결 node* back;//마지막에 바로 연결 ll size; }queue; void init(queue* q){ q->front=NULL; q->back=NULL; q->size=0; } void push(queue *q,newtype v){//qush하려면 n..

견우직녀달
'자료구조/by C' 카테고리의 글 목록