목록C, C++ (13)
배우고픈 공돌이
//main.c #include #include #include "list.h" void printInt(const void *pData) { printf("%d",*(int*)pData); } void printDouble(const void *pData) { printf("%f",*(double*)pData); } int main(void) { list_t list1, list2; initList(&list1, sizeof(int)); initList(&list2, sizeof(double)); int i=10;insertFirstNode(&list1,&i); int j = 40;insertNode(&list1,&i,&j); j = 30;insertNode(&list1,&i,&j); j = 20;in..
//main.c #include #include "queue.h" int main(void) { queue_t q1, q2; initQueue(&q1,10,sizeof(int)); initQueue(&q2,100,sizeof(double)); int i=100; push(&q1,&i); i=200; push(&q1,&i); i=300; push(&q1,&i); double j = 900.9; push(&q2,&j); j=800.8; push(&q2,&j); j=700.7; push(&q2,&j); pop(&q1,&i); printf("q1 1st pop : %d \n",i); pop(&q1,&i); printf("q1 2nd pop : %d \n",i); pop(&q1,&i); printf("q1 3rd..
//main.c #include #include "stack.h" int main(void) { stack_t s1, s2; initStack(&s1,10,sizeof(int)); initStack(&s2,100,sizeof(double)); int i=100; push(&s1,&i); i=200; push(&s1,&i); i=300; push(&s1,&i); double j = 900.9; push(&s2,&j); j=800.8; push(&s2,&j); j=700.7; push(&s2,&j); pop(&s1,&i); printf("s1 1st pop : %d \n",i); pop(&s1,&i); printf("s1 2nd pop : %d \n",i); pop(&s1,&i); printf("s1 3rd..
You have been given a string s, which is supposed to be a sentence. However, someone forgot to put spaces between the different words, and for some reason they capitalized the first letter of every word. Return the sentence after making the following amendments:Put a single space between the words.Convert the uppercase letters to lowercase.ExampleFor s = "CodefightsIsAwesome", the output should ..
#include using std::cout;using std::endl; void swap(int &ra, int &rb){int tmp = ra;ra = rb;rb = tmp;} int main(){int a = 100;int b = 200; cout
list.h #ifndef LIST_H#define LIST_H typedef struct node{struct node* next;}node_t; typedef struct {node_t *ptr;int element_size;}list_t; void initList(list_t *pListi, int element_size);void cleanupList(list_t *pList);void printList(const list_t *pList,void (*print)(const void*)); void insertFirstNode(list_t *pList, const void *pData);void insertNode(list_t *pList, const void *pPrevData, const vo..
queue.h #ifndef QUEUE_H#define QUEUE_H class Queue{private:int* pArr;int rear;int front;int size;public:Queue(int size);~Queue();void push(int data);int pop();}; #endif queue.cpp #include "queue.h"#include Queue::Queue(int size){//this-> pArr = (int*) malloc(sizeof(int)*size);this->pArr = new int[size];assert( this->pArr ); this-> size = size;this-> front =0;this-> rear = 0; } Queue::~Queue(){//..
stack.h #ifndef STACK_H#define STACK_H class Stack{private://information hidingint* pArr;int tos;int size;public:Stack(int size);//void initStack(int size);~Stack();//void cleanupStack();void push(int data);int pop();}; #endif stack.cpp #include "stack.h"#include Stack::Stack(int size){//this-> pArr = (int*) malloc(sizeof(int)*size);this-> pArr = new int[size];assert( this->pArr ); this-> size =..
3. malloc - free -> new - delete void Stack::initStack(int size){//this-> pArr = (int*) malloc(sizeof(int)*size);this-> pArr = new int[size];} void Stack::cleanupStack(){//free( this->pArr );delete [] this->pArr;} 4. init, close function -> using constructor, destructor -main.cpp int main(){ //initStack(&s1,10);initStack(&s2,100);s1.Stack(10); s2.Stack(100); //cleanupStack(&s1); cleanupStack(&s2..
c로된 코드를 c++로 변경하기 위해 8단계 정도로 나눠볼 수 있다. 1. .c -> .cpp gcc 컴파일러를 이용하여 .c파일을 컴파일 했다면, .c파일을 .cpp파일로 확장자 변경하고 g++ 컴파일러를 사용하면 컴파일 된다. 2. 함수 -> 구조체변수(객체)의 멤버함수로 변경 아래의 c코드를 예를 들어 변경한다. -main.c #include #include "stack.h" int main(void){stack_t s1, s2; initStack(&s1,10);initStack(&s2,100); push(&s1,100); push(&s1,200);push(&s1,300);push(&s2,900);push(&s2,800);push(&s2,700);printf("s1 1st pop : %d \n",p..