08 2016 档案

摘要:堆排序基本概念堆是一种数据结构,它是将一些数据放在物理数据结构:数组或者vector中;逻辑数据结构是完全二叉树。如果根节点的值大于两个子节点值,就是大根堆;如果根节点的值小于两个子节点值,就是小根堆。用堆这种数据结构来实现排序,就是堆排序。该算法的操作主要有minheapify:最小堆处理,复杂度是O(logN)find_min:找到最小值,复杂度是O(1)delete_min:删除最小值节点,... 阅读全文
posted @ 2016-08-31 17:01 gremount 阅读(230) 评论(0) 推荐(0)
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then l 阅读全文
posted @ 2016-08-26 14:19 gremount 阅读(263) 评论(0) 推荐(0)
摘要:功能:实现两个主机之间的局域网聊天实现关键:如何同时处理套接字的输入和标准输入 --- select函数客户端的程序#include "unp.h"void cli_echo(FILE *fp, int sockfd){ int maxfdp1, stdineof; fd_set rset; char buf[1000]; int n; stdineof=0; FD_ZERO(&rset); fo... 阅读全文
posted @ 2016-08-24 15:17 gremount 阅读(407) 评论(0) 推荐(0)
摘要:配置好动态链接库或者静态链接库1,下载UNIX网络编程书的头文件及示例源码unpv13e2 按照readme来编译Execute the following from the src/ directory: ./configure # try to figure out all implementation differences cd lib # buil... 阅读全文
posted @ 2016-08-24 15:15 gremount 阅读(271) 评论(0) 推荐(0)
摘要:程序的输入都建有一个缓冲区,即输入缓冲区。一次输入过程是这样的,当一次键盘输入结束时会将输入的数据存入输入缓冲区,而cin函数直接从输入缓冲区中取数据。正因为cin函数是直接从缓冲区取数据的,所以有时候当缓冲区中有残留数据时,cin函数会直接取得这些残留数据而不会请求键盘输入一. cin>>该操作符是根据后面变量的类型读取数据。输入结束条件 :遇到Enter、Space、Tab键。对结束符的处理 ... 阅读全文
posted @ 2016-08-19 18:30 gremount 阅读(366) 评论(0) 推荐(0)
摘要:背景知识如果TCP客户同时处理两个输入: 标准输入和TCP套接字. 那么如果客户阻塞于标准输入期间(例如fgets()), 套接字收到的FIN或者RST信息就不会及时得到处理. 所以这里需要使用I/O复用, 是由select和poll这两个函数支持的.为了更好地理解I/O复用, 这里总结一下UNIX下的5种I/O模型的基本区别:阻塞式I/O : 默认情况下, 所有的套接字都是阻塞的. 一些慢系统调... 阅读全文
posted @ 2016-08-18 22:11 gremount 阅读(174) 评论(0) 推荐(0)
摘要:[编程题] 洗牌洗牌在生活中十分常见,现在需要写一个程序模拟洗牌的过程。 现在需要洗2n张牌,从上到下依次是第1张,第2张,第3张一直到第2n张。首先,我们把这2n张牌分成两堆,左手拿着第1张到第n张(上半堆),右手拿着第n+1张到第2n张(下半堆)。接着就开始洗牌的过程,先放下右手的最后一张牌,再放下左手的最后一张牌,接着放下右手的倒数第二张牌,再放下左手的倒数第二张牌,直到最后放下左手的第一张... 阅读全文
posted @ 2016-08-18 21:34 gremount 阅读(271) 评论(0) 推荐(0)
摘要:Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 两个字符串A和B, 在A中查找是否出现过B, 如 阅读全文
posted @ 2016-08-15 19:49 gremount 阅读(158) 评论(0) 推荐(0)
摘要:僵死进程存在的目的 和 需要处理的原因设置僵死进程的目的是维护子进程的信息, 以便父进程在以后的某个时刻获取. 但是留存的僵死进程会占用内核的空间, 最终可能导致耗尽进程资源. 所以还是需要处理这些僵死进程.处理僵死进程的方法在服务器子进程终止时, 给父进程发送了一个SIGCHLD信号,该信号是在子进程终止时,由内核发送给父进程的一个信号. 每个信号都有一个与之关联的处置, 也称为行为. 我们可以... 阅读全文
posted @ 2016-08-15 17:09 gremount 阅读(642) 评论(0) 推荐(0)
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 该题是要求合并两 阅读全文
posted @ 2016-08-14 22:47 gremount 阅读(166) 评论(0) 推荐(0)
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这道题如果有第21题 合并两个链表的基础就会比较容易,具体合并链表的时候有两种思路 (1)如果k个li 阅读全文
posted @ 2016-08-14 22:19 gremount 阅读(188) 评论(0) 推荐(0)
摘要:TCP客户与服务器进程之间发生的重大事件时间表TCP服务器socket() --- bind() --- listen() --- accept() --- read() --- write --- read() --- closeTCP客户socket() --- connect() --- write() --- read() --- close()套接字函数简介int socket(int... 阅读全文
posted @ 2016-08-13 17:29 gremount 阅读(526) 评论(0) 推荐(0)
摘要:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array whic 阅读全文
posted @ 2016-08-08 14:47 gremount 阅读(131) 评论(0) 推荐(0)
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. 阅读全文
posted @ 2016-08-08 11:07 gremount 阅读(167) 评论(0) 推荐(0)